Nginx dynamic and static separation-configuration notes

Before clarifying the separation of movement and static, we must first understand what is movement and what is still. In web development, generally speaking, dynamic resources actually refer to those background resources, while static resources refer to files such as HTML, JavaScript, CSS, img, etc.

   Generally speaking, it is necessary to separate dynamic resources from static resources, and deploy static resources on Nginx. When a request comes, if it is a request for static resources, go directly to the static resource directory configured by nginx to obtain resources. It is a request for dynamic resources. Nginx uses the principle of reverse proxy to forward the request to the background application for processing, thereby realizing the separation of dynamic and static.

   After using front-end and back-end separation, the access speed of static resources can be greatly improved. At the same time, front-end and back-end development can be paralleled during the development process, which can effectively increase the development time and reduce the joint debugging time.

Therefore, the separation of dynamic and static is to deploy website static resources (HTML, JavaScript, CSS, img, etc. files) separately from background applications to increase the speed for users to access static codes and reduce access to background applications.
A common practice of separation of dynamics and statics : deploy static resources on nginx, deploy background projects on the application server, and dispatch static resource requests to the nginx server according to certain rules to achieve the goal of separation of dynamics and statics.

server {

        listen 80;

        server_name  hahashen.com;

        access_log  /data/nginx/logs/hahashen.com-access.log main;

        error_log  /data/nginx/logs/hahashen.com-error.log;

 

        #Dynamic access request forwarded to tomcat application processing

        location ~ .(jsp|page|do)?$ {#End with these files

           proxy_set_header  Host $host;

           proxy_set_header  X-Real-IP  $remote_addr;

           proxy_pass http://tomcat address;

        }

#Set access to static files to read directly without tomcat

location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$  {     

           expires      30d;

           root /data/hahashen/html ;

        }

}



Guess you like

Origin blog.51cto.com/15127516/2657700