


How to configure nginx and tomcat to access images and static pages
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
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
3. Put a test file under the html directory
[root@localhost html]# cat index.html this is test page !!!!
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
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 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;
5. At this time, you can test and see
First the html page
Looking at the pictures
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)
2. Unzip tomcat and start it
tar -xvf apache-tomcat-8.5.30.tar.gz [root@localhost tomcat]# sh bin/startup.sh
3. Test whether it can be accessed locally
#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/
Test access to the html page
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/
Access directly on the browser as follows
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!

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

The server does not have permission to access the requested resource, resulting in a nginx 403 error. Solutions include: Check file permissions. Check the .htaccess configuration. Check nginx configuration. Configure SELinux permissions. Check the firewall rules. Troubleshoot other causes such as browser problems, server failures, or other possible errors.

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor