How to configure nginx and tomcat to access images and static pages

PHPz
Release: 2023-05-14 08:58:12
forward
1661 people have browsed it

The first method: nginx configuration

1. Create the file path:

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

2. Put the image under the images directory

[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
Copy after login

3. Put a test file under the html directory

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

4. Install nginx and start it

It depends on your preference whether to use yum or compile. I choose to compile and formulate the installation module by 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 them

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
Copy after login

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
Copy after login

Compile and install

make && make install 
groupadd www 
useradd -g www www
Copy after login

Modify 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/;#指定图片存放路径 
   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;
Copy after login

5. At this time, you can test and see

First the html page

How to configure nginx and tomcat to access images and static pages

Looking at the pictures

How to configure nginx and tomcat to access images and static pages

Obviously, static pages and pictures can be accessed successfully under nginx settings. Let’s start tomcat access settings

Second method: tomcat

1. Check the jdk version

 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)
Copy after login

2. Unzip tomcat and start it

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

3. Test whether it can be accessed locally

How to configure nginx and tomcat to access images and static pages

#4. If the above is normal, then put the page folder under wepapps. Note that there is inde.html page in the html folder.

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

Test access to the html page

How to configure nginx and tomcat to access images and static pages

Continue to put the picture folder under wepapps. There are pictures under images.

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

Access directly on the browser as follows

How to configure nginx and tomcat to access images and static pages


The above is the detailed content of How to configure nginx and tomcat to access images and static pages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template