in order to implement nginx "reverse proxy and load balancing function, we need to use httpproxymodule and httpupstreammodule module. where httpproxymodule The function of the module is to forward the user's data request to another server, httpupstreammodule ip nginx The default auto-compile module.
When acting on a single host, thenginx configuration file is:
server {
Listen 80;
server_name aaa.com;
Location/{
Proxy_pass/HTTP 10.10.10.128 /;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
# Access_log/home/logs/aaa_access.log combined;
}
if the back-end machine has more than one (load Balancing)
N The ginx configuration file is written
Upstream BBB
{
Server 192 : 168.182.129 ;
Server 192 : 168.182.131 ;
}
server {
Listen 80;
server_name bbb.com;
Location /{
Proxy_pass http://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;
}
# Access_log/home/logs/bb_access.log combined;
}
Proxy all domain names on a server
First in the vhosts directory need to build two files, one is the servername list file, one is a virtual host configuration file
The contents of two files were
(1) servername
server_name aaa.com 111.com // in this simple line, of course, this server_name can continue to add
(2) virtual Host configuration file
server {
Listen 80;
Include Vhosts/servername; The file here is the top servername list file .
Location/{
Proxy_pass/HTTP 10.10.10.128 /; This is the server IP address that needs to be the proxy .
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
Access_log/dev/null;
}
Nginx reverse proxy, load balancer