Author: JackTian wechat public ID: Jake_Internet
This is the fourth day of my participation in Gwen Challenge
Nginx static and static separation
Nginx handles static pages, Tomcat handles dynamic pages, and Tomcat handles static pages.
Static pages
Static pages: one page for one content, that is, one-to-one relationship. In the Internet architecture, pages are almost constant or change less frequently. For example: HTML pages, JS/CSS style files and so on;
Matching technology architecture to accelerate. For example: Squid, Nginx, CDN, and the biggest advantages of static page: fast, cross-platform, cross-server.
In any case, access is only to let the server to send data to the request end, do not do script calculation and read background database, improve access speed and reduce some security risks.
Using static page method: can be divided into database and background system and foreground, there is no absolute connection between the two, so as to improve site security.
Static page characteristics
- There’s one for every web page
Fixed URL
And the web pageURL
In order to.htm
,.html
,.shtml
And so on.For the suffix
And theDoes not contain?
; - Web content is published to the web server, regardless of whether there is a user to visit, the content of each static web page will be saved on the web server, that is to say, the file saved on the server, each web page is an independent file;
- Content is relatively stable, easy to be retrieved by search engines;
- No database support, site production and maintenance of large workload, when the site information is very large, completely rely on static web page production is more difficult;
- The interactivity is poor and the function is limited.
- Fast running data;
Dynamic pages
Dynamic page: one-to-many access, through a page can return different data according to several parameters, in the Internet architecture, different users access different dynamic scene page requests, may be different pages. For example: Taobao jingdong commodity list page, Baidu search engine results page, etc.
Dynamic pages, matching the technical architecture, such as: hierarchical architecture, service-oriented architecture, database, cache architecture;
Dynamic page characteristics
- Based on database technology, can greatly reduce the workload of website maintenance;
- Using dynamic web technology can achieve more functions of the website;
- It is not a web page file that exists independently on the server, and the server returns a complete web page only when the user requests it;
- In the search engine promotion need to do certain technical processing to adapt to the requirements of the search engine;
4. Separation of noise and movement
Static and dynamic separation refers to the architectural design method of separating static and dynamic pages from different system access.
Static page: access path short, fast, a few milliseconds;
Dynamic page: long access path, slow speed, tens or even hundreds of milliseconds, architecture scalability requirements;
Static pages and dynamic pages are distinguished by different domain names.
5. Practical case of static and static separation
1, in the Nginx server environment, prepare static resources, for access, create a data directory in the root directory, and create two folders in the directory image, WWW, image folder to upload a local image, WWW folder to create an HTML file.
2 root root 4096 3月 29 19:14 image drwxr-xr-x. 2 root root 4096 3月 29 19:13 WWW # CD Image / # ls games.jpg # CD.. /www/ # ls 20200331.html # cat 20200331.html <h1>This is a static page! </h1>Copy the code
2. Modify the nginx.conf configuration file
Add listening port, access name, and location.
# vim /usr/local/nginx/conf/nginx.conf 39 server { 40 listen 80; 41 server_name 192.168.1.10. 42 43 #charset koi8-r; 44 45 #access_log logs/host.access.log main; 46 47 location /www/ { 48 # proxy_pass http://myserver; 49 root /data/; 50 index index.html index.htm; 51 } 52 location /image/ { 53 root /data/; 54 autoindex on; 55}Copy the code
3. Restart the Nginx service
# ./nginx -s stop
# ./nginx
Copy the code
4. Verify the effect
In the client browser, enter: http://192.168.1.10/image/ and http://192.168.1.10/www/20200331.html respectively test of dynamic and static separation success, delete the back-end tomcat server on a static file, see whether can visit, If the static resource is accessible, Nginx returns it directly, without having to pass through the back-end Tomcat server.
conclusion
Through this article we introduce what is Nginx static and dynamic separation, what is the static page and dynamic page and their respective characteristics, static and dynamic separation architecture design and dynamic separation practice cases;
Generally speaking, static and static separation is the original need to generate dynamic site through static site optimization technology, such as the actual situation, when the data is not large, can generate static page data is not much business, suitable for page static optimization.
The overall structure of this article is not long, but I hope you will be logical and learn from each other.
Original is not easy, if you think this article is useful to you, please kindly like, comment or forward this article, because this will be my power to output more high-quality articles, thank you!
See you next time!