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)
Use of built-in functions in the database This ar...
Table of contents About MariaDB database in Linux...
1. When the mobile terminal processes the list sl...
Preface MySQL master-slave replication is the bas...
Table of contents Preface Install Introduction Sw...
Preface I have always wanted to know how a SQL st...
Preface Bash has many important built-in commands...
MySQL DECIMAL data type is used to store exact nu...
If a div sets background-color and background-ima...
This article example shares the specific code of ...
Table of contents BOM (Browser Object Model) 1. W...
The css technique for changing the color of an im...
Table of contents Case 1: Case 2: Case 3: To summ...
question After the company migrated the server, t...
Problem description: The Linux system's netwo...