[nginx] 无法获取proxy_set_header的变量值

lfzyx
  • 251

日志格式:

log_format main '[$http_h1ost][$http_x_real_ip] [$http_x_forwarded_for] [$remote_addr] [$remote_port] [$server_addr]';

服务段:

server {  
 listen 80;  
 server_name xx.xxx.com;  
 #charset koi8-r;  
 access_log logs/access.log main ;  
 error_log logs/error.log debug;  
 location / {  
 proxy_pass http://xxx.com:8080;  
 index index.html index.htm index.jsp default.jsp index.action index.do   default.action default.do;  
 proxy_set_header h1ost $host;  
 proxy_set_header X-real-ip $remote_addr;  
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  

 }

然后我查看nginx日志,是这样的

   [-][-] [-] [16.153.69.35] [52849] [131.201.192.51]  
   [-][-] [-] [16.153.69.35] [19025] [131.201.192.51]

也就是说我自定义的变量没有获取到,然后我搜了一下,说是要配置http部分,增加underscoresinheaders on; 但也没用,求帮助啊!

遇到了奇怪的事,我在下面加了一个server

server {
    listen       80;
    server_name  test.xxx.com;
    location / {
        proxy_pass http://xx.xxx.com;
        index index.html index.htm index.jsp default.jsp index.action index.do default.action default.do;
    proxy_set_header    h1ost $host;
        proxy_set_header    X-real-ip $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

                }
    }

然后我访问test.xxx.com,不是之前的xx.xxx.com,日志就可以显示了

  [test.xxx.com][16.153.69.35] [16.153.69.35] [131.201.192.51] [46050]  [131.201.192.51]
  [test.xxx.com][16.153.69.35] [16.153.69.35] [131.201.192.51] [46052]  [131.201.192.51]
回复
阅读 8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏