Article From:https://www.cnblogs.com/lwx521/p/9967733.html

TomcatIt’s a server we often use. It’s portable and fast, but when the data is large, it will affect the speed of access and response. Then Nginx appears.

NginxIt can do reverse proxy, load balancing, dynamic and static resource separation. Here we use it to do dynamic and static separation.

Actions are dynamic pages

Quietness is a document that does not change or often changes, such as css, js, pictures, etc.

FirstInstall Nginx

Download address http://nginx.org/en/download.html, I downloaded version 1.12.2 here, and then decompressed to disk E.

cmdSwitch to the directory of nginx, enter start nginx or nginx.exe, and then you can see the nginx.exe process in the resource manager.

Enter the address directly in the browser address bar at http://localhost:80 and return. The following page shows the successful start-up.

Configure Nginx

Open the nginx.conf configuration file under the nginx file conf and modify it

 

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

location / {
#The request is forwarded to tomcat, my port number is 8888Proxy_pass http:
//localhost:8888; index ak47.html index.html index.htm; } # Forwarding of dynamic requestsLocation~ \.(jsp|do)$ { proxy_pass http://localhost:8888; proxy_set_header Host $host; } # Direct reading of static requestsLocation~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { #Static resource addressRoot E:/nginx/nginx-1.12.2/static; #expiresDefine the user browser cache for 7 days. If the static page is not updated frequently, it can be set longer, which can save bandwidth and relieve the pressure of the server.Expires 1D;} error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }

 

Then put the war tonmcat project under the webapps file

Because my dynamic pages are in the SSM folder, all my static resources are also put in the SSM folder.

E:/nginx/nginx-1.12.2/staticUnder the SSM folder,In general, the style and public folders under SSM project in webapps are cut to
E:/nginx/nginx-1.12.2/staticIt's OK under SSM, otherwise static resources can't be accessed.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *