生产环境下,有时候需要访问图片,正常需要应用ftp、nginx等配套使用,但是有时候为了简化,可以用以下的两种简单的访问,说实话,就是为了偷懒,但是效果是能有的,这就行了,所以今天做这个简化版的方便大家应急之用。

第一种方法:nginx配置下

1、创建文件路径:

[root@localhost /]# mkdir /data/soft/
[root@localhost ~]# cd /data/soft/
[root@localhost soft]# mkdir html images

2、在images目录下面放入图片

[root@localhost soft]# cd images/
[root@localhost images]# ll
总用量 80
-rw-r--r--. 1 root root  9503 4月  25 17:06 thPZFULFJN.jpg
-rw-r--r--. 1 root root 16083 4月  25 17:06 thR2C5VCMZ.jpg
-rw-r--r--. 1 root root 12218 4月  25 17:06 thRG3YX53T.jpg
-rw-r--r--. 1 root root 15048 4月  25 17:06 thSUF51VTR.jpg
-rw-r--r--. 1 root root 21799 4月  25 17:06 thVWSLF8ZE.jpg

3、在html目录下面放入一个测试文件

[root@localhost html]# cat index.html
this is test page !!!!

4、安装nginx,并启动

选用yum还是编译看自己喜好,我选择编译,自己制定安装模块

解压pcre-8.34.tar.gz zlib-1.2.8.tar.gz openssl-1.0.1g.tar.gz三个包并安装

tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure && make && make install

tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure && make && make install

tar -zxvf openssl-1.0.1g.tar.gz
cd openssl-1.0.1g
./config && make && make install

安装Nginx

tar -zxvf nginx-1.9.0.tar.gz
cd nginx-1.9.0
#./configure --prefix=/data/soft/nginx \
--user=www \
--group=www \
--with-mail \
--with-mail_ssl_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_sub_module \
--with-http_spdy_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre=/data/src/pcre-8.34 \
--with-zlib=/data/src/zlib-1.2.8 \
--with-openssl=/data/src/openssl-1.0.1g

编译并安装

make && make install
groupadd www
useradd -g www www

修改nginx配置文件

[root@localhost nginx]# vim conf/nginx.conf
      server {
                listen 80;
                server_name localhost;

                #charset koi8-r;

                #access_log logs/host.access.log main;

                location ~ .*\.(gif|jpg|jpeg|png)$ {
                        expires 24h;
                       root /data/soft/images/;#指定图片存放路径
                       access_log /data/soft/nginx/logs/images.log;#日志存放路径
                       proxy_store on;
                       proxy_store_access user:rw group:rw all:rw;
                       proxy_temp_path /data/soft/images/;#图片访问路径
                       proxy_redirect off;
                       proxy_set_header Host 127.0.0.1;
                       client_max_body_size 10m;
                       client_body_buffer_size 1280k;
                       proxy_connect_timeout 900;
                       proxy_send_timeout 900;
                       proxy_read_timeout 900;
                       proxy_buffer_size 40k;
                       proxy_buffers 40 320k;
                       proxy_busy_buffers_size 640k;
                       proxy_temp_file_write_size 640k;
                       if ( !-e $request_filename)
                       {
                                 proxy_pass http://127.0.0.1;#默认80端口
                       }
         }

                      location / {
                      root /data//soft/html; #html访问路径
                      index index.html index2.htm; #html文件名称
                      }
          }

                      error_page 404 /404.html;

5 、此时可以测试看看

先是html页面

在看看图片

显然,nginx设置下静态页面和图片是可以访问成功的,下面开始tomcat访问设置

第二种方法:tomcat

1、查看jdk版本

 java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

2、解压tomcat并启动

tar -xvf apache-tomcat-8.5.30.tar.gz [root@localhost tomcat]# sh bin/startup.sh 

3、本地测试能不能访问

4、 上面正常,那么把页面文件夹放到wepapps下面去,注意,html文件夹里有inde.html页面的。

 [root@localhost soft]# cp -rp html/ /data/soft/tomcat/webapps/

测试访问html页面

继续把图片文件夹放到wepapps下面去,images下面是有图片的。

[root@localhost images]# cp -rp /data/soft/images/ /data/soft/tomcat/webapps/ 

直接在浏览器上访问如下

总结:这样,简单的图片访问和html页面访问就可以使用了,非常方便,这两个方法非常适用内网环境,对于运维来说是个不错的选择。

最新文章

  1. node实现watcher的困境
  2. POJ Minimum Cut
  3. C#/PHP调用有SoapHeader的WebService
  4. 剑指Offer面试题:29.丑数
  5. 【转】js 关键字 in 的使用方法
  6. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  7. Addthis使用
  8. 利用Quartz2D推图的另一个方法 (使用CGMutalePathRef进行分层次)
  9. linux命令:mkdir命令
  10. Go Walk教程 - 流程控制( switch)
  11. ArcGIS Desktop 10.0 直连 ArcSDE 10.2
  12. Squid故障
  13. Js判断密码强度并显示提示信息
  14. HTML基础总结<文本格式>
  15. java.lang.NoClassDefFoundError: org.ksoap2.transport.HttpTransportSE异常处理
  16. 用css样式围剿等高列问题(转载)
  17. 在 .NET 4 中使用托管可扩展性框架构建可组合的应用程序
  18. 享受release版本发布的好处的同时也应该警惕release可能给你引入一些莫名其妙的大bug
  19. Docker 部署
  20. 手机端仿ios的三级联动脚本四

热门文章

  1. python学习 day4 (3月5日)---列表
  2. windows无法卸载jdk的解决方法
  3. 整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建
  4. 【转】Linux useradd
  5. 2019.02.06 bzoj2987: Earthquake(类欧几里得)
  6. 2018.11.06 bzoj1040: [ZJOI2008]骑士(树形dp)
  7. Servlet中(Session、cookies、servletcontext)的基本用法
  8. python3 提示 name ‘reload’ is not defined
  9. lambda表达式(c++11)
  10. BZOJ 4765 普通计算姬 (分块 + BIT)