nginx location配置

nginx location配置出现too many Host headers 错误

检查具体配置如下: 

 location  /monitor/ {
  proxy_set_header Host $host;
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $host;  
  proxy_pass  http://127.0.0.1:9001;
}

发现Host的配置重复,导致设置出错请求无法继续传递到后端

将多余的   proxy_set_header Host $host; 删除即可; 

location 路径下子路径的配置,

如果存在/monitor/xx1    /monitor/xx2   不用对每一个路径进行配置,直接/ 即可

#location /monitor/click   {
#  proxy_set_header Host $host;
#  proxy_pass  http://127.0.0.1:9001;
#}

#location /monitor/deliver    {
#  proxy_set_header Host $host;
#  proxy_pass  http://127.0.0.1:9001;
#}

location  /monitor/ {
  proxy_set_header Host $host;
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass  http://127.0.0.1:9001;
}

 

tip 如果设置反向代理的话使用ip 不能使用域名,使用域名会导致循环查找的bug 

upstream xxx{
    server 127.0.0.1:23456;
}

或者

proxy_pass   http://127.0.0.1:23456;

 

禁止: proxy_pass http://xx.xxx.com;

 

posted on 2019-05-14 16:10  iokde.com  阅读(178)  评论(0编辑  收藏  举报

导航