1, first create a new configuration file,/etc/nginx/sites-enabled/reverse-proxy.conf
nginx reverse proxy
The contents are as follows, nginx proxy manager each line requires a semicolon ending
nginx proxy_pass
Upstream Monitor_server #这里是为了使用负载均衡, so that multiple IP can provide the same service, weight for the right value,
server 10.10.12.203:8080 weight=2; # The higher the weight value, the greater the probability of being selected
server 10.10.12.202:8080 weight=4;
Server
{
listen 8081;
server_name www.xxx123.com; # Reverse Domain name agent, different domain name is to point to the same access IP, after Nginx, and to different internal IP to provide network services, "www" Do not omit
location/{
proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header x-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass http://monitor_server
}
}
Server
{
listen 8081;
server_name localhost;
Location/{
proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header x-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass http://10.10.12.203:8080
}
}
2, the above configuration file include to nginx.conf
Edit/etc/nginx/nginx.conf, add a word in http{}, such as
Include/etc/nginx/mime.types;nginx proxy
Default_type Application/octet-stream;
Add a sentence below two lines:jwilder nginx proxy
include/etc/nginx/sites-enabled/reverse-proxy.conf;nginx reverse proxy example
In this way, you can refer to the reverse proxy configuration file, nginx reverse proxy docker and then restart it: Service nginx restart
3, test
My test client is Windows,ip 10.10.12.73 While the Nginx server is in Ubuntu and IP is 10.10.2.176.
Open the C:\windows\System32\drivers\etc\hosts file and add the following at the end:
10.10.2.176 www.xxx123.com
Where 10.10.2.176 for the Nginx server IP, the results can be entered in the browser www.xxx123.com, you can see it was forwarded.