Home>Article>Operation and Maintenance> How nginx realizes dynamic and static separation

How nginx realizes dynamic and static separation

(*-*)浩
(*-*)浩 Original
2019-07-15 11:50:27 6893browse

In order to speed up the parsing speed of the website, dynamic pages and static pages can be parsed by different servers to speed up the parsing speed. Reduce the pressure on a single server.

How nginx realizes dynamic and static separation

Prepare an nginx proxy for two http to handle dynamic and static respectively. You can also let nginx proxy parse static web pages by itself, but it feels quite stressful to have nginx proxy and parse websites at the same time.

The important configuration of nginx here is as follows.

location / { root /var/www/html/upload; index index.php index.htm; } location ~ .*\.(html|gif|jpg|png|bmp|swf|jpeg)$ { proxy_pass http://192.168.43.22:80; } location ~ \.php$ { proxy_pass http://192.168.43.62:80; }

The role of location /

defines that nginx goes to /var/www/html/upload to look for index.php when it finds it index.php matches the following regular pattern location ~ \.php$.

location ~ \.php$ The role of

Anything ending with php will be forwarded to http (192.168.43.62) by proxy, and http1 will process it , here http1 needs to look at its own configuration file, define the website root directory /var/www/html/upload in its own configuration file, find .index.php and then process the parsing and return it to nginx.

Location ~ .*\.(html|gif|jpg|png|bmp|swf|jpeg)$ The role of

Static pages such as html are Leave it to http2 (192.168.43.22) for processing. http2 finds its own website directory and returns it to nginx.

The two https must be placed in the same directory, but the tasks of each server are different.

The agent itself must have a directory of the website, because the top location / will take effect first. If there is no directory, it will directly prompt that the directory cannot be found, and no further matching will be performed.

The three servers store the website in the same directory and the website files are the same. The root directory of the http configuration file must be specified correctly.

For more Nginx related technical articles, please visit theNginx usage tutorialcolumn to learn!

The above is the detailed content of How nginx realizes dynamic and static separation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn