nginx反代配置tips

发布时间 2023-07-19 16:20:44作者: Lixin-Link

nginx轮训导致验证码不正确

在upstream里添加ip_hash;,例子:

http {
    upstream test {
        # 这样同一台电脑会一直访问到同一台机器
        ip_hash;
        server 172.0.0.1:8080;
    }
}

静态资源访问出错

在location里重写header:

server {
    location / {
        index  index.html index.htm;
        proxy_pass http://test;
        # 重写header
        proxy_set_header  Host $http_host;
        proxy_set_header  X-Real-IP $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

To be continued...