In order to speed up the parsing of the website, dynamic pages and static pages can be parsed by different servers to speed up the parsing speed. Reduce the pressure on the original single server. To put it simply, it uses regular expressions to match and filter, and then sends them to different servers. 1. Prepare the environment Prepare an nginx proxy for two http to handle dynamic and static respectively. 1. Configure the compiled and installed nginx as a reverse proxy upstream; upstream static { server 10.0.105.196:80 weight=1 max_fails=1 fail_timeout=60s; } upstream php { server 10.0.105.200:80 weight=1 max_fails=1 fail_timeout=60s; } server { listen server_name #Dynamic resource loading 80; localhost location ~ \.(php|jsp)$ { proxy_pass http://phpserver; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #Static resource loading location ~ \.(html|jpg|png|css|js)$ { proxy_pass http://static; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } Static resource configuration---10.0.105.196 server { listen 80; server_name localhost; location ~ \.(html|jpg|png|js|css)$ { root /var/www/nginx; } } Upload pictures Dynamic resource configuration: 10.0.105.200 yum install php7.1
Edit the nginx configuration file:
127.0.0.1:9000; #Specify the access address index.php; #Specify the default file SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_params; #Contains nginx constant definitions When accessing a static page, the location matches (html|jpg|png|js|css) and is forwarded to the static server. The static service is The regular match of location is used to process the request. When accessing a dynamic page, the location matches the file ending with .\php and forwards it to the backend PHP service to process the request. Knowledge point expansion: Detach by request [root@lb01 conf]# vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream stack_pools { server 172.25.254.134:80 weight=5; } upstream dynamic_pools { server 172.25.254.135:80 weight=5; } server { listen 80; server_name www.lbtest.com; location / { root html; index index.html index.htm; proxy_set_header Host $host; proxy_pass http://dynamic_pools; } location /image/ { proxy_set_header Host $host; proxy_pass http://stack_pools; } location /dynamic/ { proxy_set_header Host $host; proxy_pass http://dynamic_pools; } } } [root@lb01 conf]# nginx -s reload Separate by extension [root@lb01 conf]# vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream stack_pools { server 172.25.254.134:80 weight=5; } upstream dynamic_pools { server 172.25.254.135:80 weight=5; } server { listen 80; server_name www.lbtest.com; location / { root html; index index.html index.htm; proxy_set_header Host $host; proxy_pass http://dynamic_pools; } location ~ .*.(jpg|png|gif|css|js|swf|bmp|jsp|php|asp)$ { proxy_set_header Host $host; proxy_pass http://stack_pools; } } } [root@lb01 conf]# nginx -s reload This is the end of this article about the example of implementing dynamic and static separation with nginx. For more relevant content about implementing dynamic and static separation with nginx, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: JS implements the rock-paper-scissors game
>>: MySQL 8.0.18 installation tutorial under Windows (illustration)
Hello everyone, I am Liang Xu. When using Linux, ...
Written in front I don’t know who first discovere...
CSS3 can create animations, which can replace man...
What is MyCAT A completely open source large data...
a href="#"> After clicking the link, ...
April 23, 2020, Today, Ubuntu 20.04 on Windows al...
Table of contents 1. Arithmetic operators 2. Comp...
Introduction Recently, I needed to make a barrage...
Table of contents 1. System Information 2. Shutdo...
Preface Docker can configure environment variable...
This article records the installation and configu...
<br />This is not only an era of information...
MySQL creates users and authorizes and revokes us...
Table of contents 01 What is the essence of a con...
MySQL is a relatively easy-to-use relational data...