first of all, according to the directory accessed to distinguish the back end of W eb:
My requirement: When the requested directory is/aaa/sends the request to machine A, when the requested directory is/bbb/sends the request to machine B, except the directory/aaa/and the directory/bbb/, the other request sends to machine B
The contents of my configuration file are:
Upstream aaa.com
{
Server 192.168.111.6;
}
Upstream bbb.com
{
Server 192.168.111.20;
}
server {
Listen 80;
server_name li.com;
location/aaa/
{
Proxy_pass http://aaa.com/aaa/;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
location/bbb/
{
Proxy_pass http://bbb.com/bbb/;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
Location/
{
Proxy_pass http://bbb.com/;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
}
Copy Code
Description:
more than 1 of the aaa.com and bbb.com in the configuration file are custom and write-free.
2 The server in upstream can write multiple, for example
Upstream aaa.com
{
server 192.168.111.6;
server 192.168.111.4;
server 192.168.111.5;
}
3 Proxy_passhttp://aaa.com/aaa/You must add this directory here, or you will have access to the root directory.
4 Actually, in the above configuration file, the localtion/bbb/part can be omitted, because the back location/already contains the/bbb/, so even if we do not define localtion/bbb/will also access to bbb.com.
Nginx proxies for the requested URI:
Scene: 1 nginx to proxy 4 Apache
Requirements: Proxy to different Apache according to different request URI
The Nginx configuration file is:
Upstream AA.com {
Server 192.168.0.121;
Server 192.168.0.122;
}
Upstream bb.com {
Server 192.168.0.123;
Server 192.168.0.124;
}
server {
Listen 80;
server_name www.abc.com;
Location ~ aa.php
{
Proxy_pass http://aa.com/;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
Location ~ bb.php
{
Proxy_pass http://bb.com/;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
}
Nginx Proxy Load Balancer--according to the access directory and according to the different Apache