Configuration method for nginx and tomcat to access pictures

 

 

Part 1: Under nginx configuration

Create file path:

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

 Put images in the images directory

[root@localhost soft]# cd images/
[root@localhost images]# ll
Total dosage 80
-rw-r - r--. 1 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

Put a test file under the html directory

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

 Install nginx:

vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl = http: //nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

 Install nginx and start

Whether you choose yum or compile depends on your preferences. I choose to compile and make the installation module myself.

Unzip the three packages of pcre-8.34.tar.gz zlib-1.2.8.tar.gz openssl-1.0.1g.tar.gz and install

 

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

 

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

 compile and install

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

 Modify the nginx configuration file

[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/;#Specify the image storage path access_log /data/soft/nginx/logs/images.log;#Log Storage path proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /data/soft/images/;#image access path 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;#default port 80 } }

        location / { root /data//soft/html; #htmlAccess path index index.html index2.htm; #htmlFile name        

 You can test it now

first html page

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324856338&siteId=291194637