配置反向代理
server{ listen 8001; server_name 10.202.203.29; location / { proxy_pass http://10.200.80.21; } } server{ listen 8002; server_name localhost; location / {proxy_pass http://10.200.151.28;} }
访问http://10.202.203.29:8001 打开10.200.80.21
访问http://10.202.203.29:8002 打开10.200.151.28
还可以配置有端口的
server { listen 80; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; } }
这样的话80端口的访问都会转发到5000端口
负载均衡
server{ listen 8001; server_name 10.202.203.29; location / { proxy_pass http://backend; } } upstream backend { server 10.200.151.28; server 10.200.80.21; }