linux - [nginx] 无法获取proxy_set_header的变量值
迷茫
迷茫 2017-04-17 11:33:05
[Linux讨论组]

日志格式:

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]
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号