Nginx Topic (3)--Static and dynamic separation

nginx dynamic and static separation

In order to improve the response speed of the website and reduce the load of the program server (Tomcat, Jboss, etc.), static resources, such as pictures, js, css and other files, can be cached in the reverse proxy server, so that the browser requests a static resource. , the proxy server can process the request directly without forwarding the request to the backend server. For dynamic files requested by users, such as servlet and jsp, they are forwarded to Tomcat and Jboss server for processing, which is the separation of dynamic and static. That is, the separation of dynamic files and static files.

Principle of dynamic and static separation

Dynamic and static separation can match the request url through location, and deploy website static resources (HTML, JavaScript, CSS, img and other files) separately from background applications to improve the speed of users' access to static code and reduce access to background applications. Usually static resources are placed in nginx, and dynamic resources are forwarded to the tomcat server.
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-6DOYO4Fb-1690195463244)(vx_images/152464491826923.png)]

configuration

    location / {
           proxy_pass http://static_server;
     }
    location ~  .*\.(css)$  {
         root   /usr/share/nginx/dss;
     }
     location ~ .*\.(htm|html|gif|jpg|jpeg|png|gif|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma) {
         proxy_pass http://static_server;
         expires 5d;
     }
     location ~ .*\.jsp$ {
         proxy_pass http://tomcat_server;
         expires 1h;
     }

Guess you like

Origin blog.csdn.net/Artisan_w/article/details/131902728