V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
lfzyx
V2EX  ›  NGINX

无法获取proxy_set_header的变量值

  •  
  •   lfzyx ·
    lfzyx · 2013-11-14 10:06:47 +08:00 · 3200 次点击
    这是一个创建于 3815 天前的主题,其中的信息可能已经有所发展或是发生改变。
    日志格式:
    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;

    }


    然后我查看日志记录,是这样的
    [-][-] [-] [133.126.116.250] [52849] [131.201.192.51]
    [-][-] [-] [133.126.116.250] [19025] [131.201.192.51]


    也就是说我自定义的变量没有获取到,然后我搜了一下,说是要配置http部分,增加underscores_in_headers on;
    但也没用,求帮助啊!
    第 1 条附言  ·  2013-11-14 17:21:48 +08:00
    遇到了奇怪的事,我在下面加了一个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]
    5 条回复    1970-01-01 08:00:00 +08:00
    julyclyde
        1
    julyclyde  
       2013-11-14 11:02:13 +08:00
    proxy_set_header是给后面服务器看的
    lfzyx
        2
    lfzyx  
    OP
       2013-11-14 11:04:43 +08:00
    @julyclyde 什么意思?那我有什么办法去看这个值获取了没有呢?
    julyclyde
        3
    julyclyde  
       2013-11-14 12:03:15 +08:00
    @lfzyx proxy_pass的目标,也就是那个http://xxx.com:8080的服务器才能看到这个header
    你这里是看不到的
    Kvm
        4
    Kvm  
       2013-11-14 13:28:58 +08:00
    [$http_x_real_ip]去掉

    $http_h1ost应该是$http_host
    lfzyx
        5
    lfzyx  
    OP
       2013-11-14 13:30:40 +08:00
    @Kvm 服务段我自定义了变量啊,不用nginx自带的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3137 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:44 · PVG 22:44 · LAX 07:44 · JFK 10:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.