【发布时间】:2020-11-25 15:16:57
【问题描述】:
我工作的公司使用 Nginx 作为反向代理和负载均衡器,所以我只是在 nginx.conf 文件中添加另一个块,如下所示用于新服务,当使用 curl http://10.11.12.15:8080/api 请求 Nginx 服务器时,Nginx 返回 400错误请求,但是在将此配置 proxy_set_header Host $http_host:$proxy_port; 更改为 proxy_set_header Host $host:$server_port; 后解决了错误请求问题。但我不明白这一点。
我已经阅读了What's the difference of $host and $http_host in Nginx 和Practical difference of $http_host and $host 的答案。
但是对于这种情况没有明确的答案。这个标头有什么区别?
proxy_set_header Host $http_host:$proxy_port;
proxy_set_header Host $host:$server_port;
使用过这个方块;
upstream web-service {
server 10.11.12.13:8080;
server 10.11.12.14:8080 backup;
}
server {
listen 8080;
server_name myHost 10.11.12.15;
location / {
proxy_pass http://web-service;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host:$proxy_port; # Throw HTTP 400 Bad Request
# proxy_set_header Host $host:$server_port; # Working solution
}
}
【问题讨论】:
标签: nginx nginx-reverse-proxy nginx-config