


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 are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINXUnit supports multiple programming languages and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

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


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor