场景一:主机内容不同
nginx代理的后端几台服务器内容不同
由于主机有限现用一台主机不同端口来模拟三台主机的不同ip
| name | 公网ip | 内网ip |
|---|---|---|
| node1 | 116.63.97.132 | 172.16.0.168 |
| node2 | 116.63.57.34:{9001,9002,9003} | 172.16.0.94 |
修改被代理主机配置文件:
[root@node2 ~]# vi /etc/nginx/nginx.conf......server { #三个server分别用不同的端口来模拟三台不同的主机listen 9001 ;server_name lcoalhost;default_type text/json;location / {return 200 '<h1>9001</h1>'; #可以是}}server {listen 9002 ;server_name lcoalhost;default_type text/json;location / {return 200 '<h1>9002</h1>';}}server {listen 9003 ;server_name lcoalhost;default_type text/json;location / {return 200 '<h1>9003</h1>';}}
修改nginx代理主机:
[root@node1 ~]# vim /etc/nginx/nginx.conf......#添加一个server块server {listen 8080 ; #通过8080来访问+/server{1,2,3}来访问不同主机server_name localhost;location /server1 {proxy_pass http://116.63.57.34:9001/;}location /server2 {proxy_pass http://116.63.57.34:9002/;}location /server3 {proxy_pass http://116.63.57.34:9003/;}}


