Nginx代理设置 Host 和 X-Forward-For

nginx配置代理请求,将包含 /a 前缀路径的请求,转发服务器 https://test.com:8088, 在server层级内配置转发规则,依然404找不到路由,增加一行设置Host后可以正常访问

location /a {
    proxy_pass               https://test.com:8088;
}
location /a {
    proxy_pass               https://test.com:8088;
    proxy_set_header Host    test.com:8088;
}		

如果不是特定端口,是80或者443。应该如下配置就可以。

location /a {
    proxy_pass               https://test.com;
    proxy_set_header Host    $http_host;
}

另一个有用的header设置是:“proxy_set_header X-Forward-For $remote_addr; ”可以将ip设置成客户端请求ip。

posted @ 2024-06-14 17:42  熊先生不开玩笑  阅读(359)  评论(0)    收藏  举报