Nginx-- static and dynamic separation configuration

Static and dynamic separation

Nginx static and dynamic separation is simply to separate dynamic with static requests can not be understood as just a simple static pages to dynamic pages and physical separation. Strictly speaking it should be dynamic with static requests separate request, it can be understood as using Nginx handling static pages, Tomcat handle dynamic pages. In terms of implementation separating movement roughly divided into two types:

  • One is the purely static files into separate independent domain name, on a separate server, is currently the mainstream respected programs;
  • Another way is to mix together the dynamic with static files released to separate by Nginx.

Specify a different suffix to achieve different requests forwarded by location. By expires parameter settings, you can make the browser cache expiration time, reduce traffic and requests before the server.

Expires specific definitions: a resource is to set an expiration time, that is to say without having to go to the server to verify, confirm directly through the browser itself has expired can be, so it will not generate additional traffic. This method is ideal for resources that change infrequently (if frequently updated files, is not recommended to cache Expires).

We set up here 3d, represents an access within three days of this URL, send a request to the server than the last file update time does not change, it will not crawl from the server returns a status code 304, if modified, the direct re-download from the server returns a status code 200.

Here Insert Picture Description

Ready to work:
Two new files in the / Users / acton_zhang / software / data folder to store static resources:

  • WWW (storage html): where placed in a a.html
  • image (stored pictures): In which put a timg.jpeg

Here Insert Picture Description

Configuration Nginx:
Here Insert Picture Description

Browser Access: localhost / image /
Because the configuration of the autoindex, so the file list:
Here Insert Picture Description
click on the link, display pictures:
Here Insert Picture Description

Browser Access: localhost / www / a.html
Show page content:
Here Insert Picture Description

Published 676 original articles · won praise 1910 · Views 240,000 +

Guess you like

Origin blog.csdn.net/cold___play/article/details/104084925