Nginx realizes simple static and dynamic separation

Source: Internet
Author: User
Tags nginx server tomcat server

The author recently began to learn to improve the Web performance aspects of knowledge. This article will introduce the use of Nginx to do distributed deployment, to achieve static separation, and analysis of performance.

Static and dynamic separation, that is, CSS, JS, jpg and other static resources and JSP dynamic resources, such as processing, to improve server response speed, improve performance.

The following examples are given to achieve static and dynamic separation, where static resources, such as CSS, JS, jpg, etc. by the Nginx server processing, direct access to disk resources, dynamic resources, such as JSP by the Tomcat server processing.

First configure Nginx.

The specific configuration of the nginx.conf is as follows:


The Nginx server acts as a proxy server, listens to 80 ports, and determines if access to dynamic resources is handled by a Tomcat server listening on port 8080, otherwise accessing static resources in the local Disk HTML folder.

Start the Nginx server and Tomcat server, Access port 80 in the browser, and view the Firefox browser's developer tools as follows:




It can be found that static resources are directly obtained from the disk, the response header has the Cache-control field, the static resource request time is 0ms.

Using the 8080-port access page directly, you get the following:


Each resource requires a 1-3ms to be fetched, and the response header has no cache-control field. Thus, static and dynamic separation has been achieved.

Also using the AB instruction for stress testing, the results are as follows:

Static and dynamic separation:



No static separation:


You can also see the performance of the static separation version is better, the total time *1000 (because the value is too small), throughput rate, transmission rate to make a bar chart comparison is as follows:

The performance level is obvious.

The above content is only the simplest use of nginx, nginx to raise high-performance content there are many, including caching and so on. I will continue to learn, update the blog.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.