1. First create a new configuration file, /etc/nginx/sites-enabled/reverse-proxy.conf
The content is as follows. Each line needs to end with a semicolon
upstream monitor_server {<span style="white-space:pre"> </span>#这里是为了使用负载均衡,使得多个ip可以提供同一个服务,weight为权值, server 10.10.12.203:8080 weight=2; server 10.10.12.202:8080 weight=4; } server { listen 8081; server_name www.xxx123.com;<span style="white-space:pre"> </span># 反向域名代理,不同的域名是指向同一入口ip,经过nginx,又转向不同的内部ip提供网络服务,"www"不省略 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; } }
Edit /etc/nginx/nginx.conf and add a sentence in http{}, such as
include /etc/nginx/mime.types;
default_type application/octet-stream;
two lines Add a sentence below:
include /etc/nginx/sites-enabled/reverse-proxy.conf;
In this case, you can reference the reverse proxy configuration file and restart: service nginx restart
3 , test
My test client is windows, the ip is 10.10.12.73; and the nginx server is in Ubuntu, the ip is 10.10.2.176.
Open the c:windowsSystem32driversetchosts file and add the following at the end:
10.10.2.176 www.xxx123.com
10.10.2.176 is the ip of the nginx server. As a result, you can enter www.xxx123.com in the browser and you can see that it is forwarded.
The above introduces Nginx configuration reverse proxy, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.