In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to realize the Nginx dynamic and static separation configuration". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Nginx dynamic and static separation configuration how to achieve" it!
I. Overview 1.1 the difference between dynamic pages and static pages
Static resource: when a user visits this resource multiple times, the source code of the resource will never change.
Dynamic resources: when users visit this resource multiple times, the source code of the resource may send changes.
1.2 what is the separation of movement and movement
The dynamic and static separation is to make the dynamic web pages in the dynamic website distinguish between the immutable resources and the frequently changing resources according to certain rules. after the dynamic and static resources are split, we can cache them according to the characteristics of the static resources. this is the core idea of website static processing.
The simple summary of dynamic and static separation is: the separation of dynamic files and static files.
Pseudo-static: if the website wants to be searched by search engines, dynamic page static technology, freemarker and other template engine technologies
1.3 Why should static and dynamic separation be used?
In our software development, some requests need to be processed in the background (such as .jsp, .do, etc.), and some requests do not need to be processed in the background (such as: css, html, jpg, js, etc.). These files that do not need to be processed in the background are called static files, otherwise dynamic files. So we ignore static files in the background. Some people will say that it will be over if I ignore static files in the background. Of course, this is OK, but in this way, the number of requests in the background increases significantly. When we have a requirement for the response speed of resources, we should use this dynamic and static separation strategy to solve the problem.
Static and static separation deploys 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. Here we put static resources into nginx and dynamic resources are forwarded to the tomcat server.
Therefore, the dynamic resources are forwarded to the tomcat server and we use the reverse proxy mentioned earlier.
2. analysis of the architecture of static and dynamic separation by Nginx.
2.2 configuration
The principle of static and dynamic separation is very simple. You can match the request url through location. Create / static/imgs under / Users/Hao/Desktop/Test (any directory) and configure it as follows:
# static resource access server {listen 80; server_name static.jb51.com; location / static/imgs {root / Users/Hao/Desktop/Test; index index.html index.htm;}} # dynamic resource access server {listen 80; server_name www.jb51.com; location / {proxy_pass http://127.0.0.1:8080; index index.html index.htm;}}
Another configuration by access to resources
Server {listen 80; server_name jb51.net; access_log / data/nginx/logs/jb51.net-access.log main; error_log / data/nginx/logs/jb51.net-error.log; # dynamic access request is transferred to tomcat App processing location ~. (jsp | page | do)? ${# proxy_set_header Host $host ending with these files Proxy_set_header X-Real-IP $remote_addr; proxy_pass http://tomcat address;} # set access static files to be read directly without going through tomcat location ~. *. (htm | html | gif | jpg | jpeg | png | bmp | swf | ioc | rar | zip | flv | mid | doc | ppt | pdf | xls | mp3 | wma) ${# expires 30d ending with these files; root / data/web/html;}} 3. The difference between static and dynamic separation and pre-and post-separation:
Dynamic and static separation dynamic resources and static resources are separated and will not be deployed on the same server.
Front and back separation: website architecture mode, micro-service development based on SOA for server development, background and front end use call interface. Split a project into a control Web (front end) and interface (back end), eventually using rpc remote invocation technology. The view layer and the business logic layer are separated, and the RPC remote calling technology is adopted in the middle.
IV. Some questions
Why is the static resource url followed by a timestamp in an Internet company project? His role: control the cache
Purpose: the ultimate goal is to control the conflict between salary static resources and old browser cache static resources when the project is online.
Solution: add timestamp specification t = project launch
304 take the local cache status code principle:
The default browser image cache is 7 days.
When the resource is downloaded for the first time, the client saves the time to modify the resource
When downloading resources for the second time, the server determines whether the last modification time of the client needs to return 200 or 304.
When downloading the resource for the second time, the server determines whether the time of the current resource file and the last modification of the client needs to return 20000 or 304.The client downloads the resource for the second time and the last modification time is 11:07:11 on 2018-6-28.
The last modification time of the server is longer than the last modification time of the client. 200 newly loaded resources
The time of the last modification on the server side is less than that on the client side. Return 304 to the local cache.
The last modification time of the js css in the production environment and the last modification time of the client cache may result in
Conflict. The server was launched on May 22, 2018, and users visited on June 01, 2018. The last modification of the new js file will be retained on June 5, 2018. So generally speaking, when the server goes online, it will add a timestamp to the static resource to force the latest resource.
At this point, I believe you have a deeper understanding of "how to achieve Nginx dynamic and static separation configuration". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.