知识点:
server的语法:
upstream语法:
upstream中192.168.100.1不是ip只是个标识,只要和下面的proxy_pass 对应即可。
基于IP的虚拟主机:
listen和server_name中多加上端口也没问题
listen可以监听在虚拟ip上面
代码:
upstream 192.168.100.1{
server 10.10.30.100:8081 backup;
server 10.10.30.101:8081 max_fails=3 fail_timeout=5s;
server 10.10.30.102:8081 max_fails=3 fail_timeout=5s; #健康状态检测
}
server {
listen 192.168.100.1:8020;
server_name 192.168.100.1:8020;
location / {
index index.jsp;
proxy_pass http://192.168.100.1;
proxy_cookie_path /192.168.100.1/ /;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /download/ {
root html;
}
}
#存在iptables的情况下记得开启iptables的端口