: This article mainly introduces NGINX Reverse proxy and dynamic/static combination. For more information about PHP tutorials, see. NGINX Reverse proxy and dynamic/static combination
I. default polling mode
Benefit: each request is distributed to different backend servers one by one in chronological order. if the backend server is down, it can be automatically removed.
Http {
Include mime. types;
Default_type application/octet-stream;
# Tcp_nopush on;
Keepalive_timeout 65;
# Configure the reverse proxy. The two machines configured can be multiple
Upstream test {
Server 192.168.136.139: 80;
Server 192.168.136.136: 80;
}
Server {
# Port number
Listen 80;
# Domain name
Server_name localhost;
# Access configuration
Location /{
Root html;
Index index.html index.htm;
}
# Objects that encounter an error jump
Error_page 500 502 503 x.html;
# Accessed Directory
Location =/50x.html {
Root html;
}
Location ~ \. Php $ {
Proxy_pass http: // test; cannot be followed by/http: // test /.
}
# Configure Dynamic/static combination
Location ~ . * \. (Html | htm | gif | jpg | jpeg | bmp | png | ico | txt | js | css) $
{
# Access Directory
Root/test/web;
Expires 3d;
}
}
II. weight Round Robin
Specify the round-robin probability. weight is proportional to the access ratio, which is used when the backend server performance is uneven.
For example:
Upstream bakend {
Server 192.168.159.10 weight = 5;
Server 192.168.159.11 weight = 10;
}
III. ip_hash (ip-based hash allocation policy)
Each request is allocated according to the hash result of the access ip address, so that each visitor accesses a backend server at a fixed time, which can solve the session problem.
For example:
Upstream resinserver {
Ip_hash;
Server 192.168.159.10: 8080;
Server 192.168.159.11: 8080;
}
4. fair (third-party) based on service response
Requests are allocated based on the response time of the backend server. requests with short response time are prioritized.
Upstream resinserver {
Server server1;
Server server2;
Fair;
}
The above introduces the NGINX Reverse proxy, dynamic and static combinations, including the content, hope to be helpful to friends who are interested in PHP tutorials.