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 · Nov 14, 2013 · 3956 views
    This topic created in 4648 days ago, the information mentioned may be changed or developed.
    日志格式:
    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;
    但也没用,求帮助啊!
    Supplement 1  ·  Nov 14, 2013
    遇到了奇怪的事,我在下面加了一个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 replies    1970-01-01 08:00:00 +08:00
    julyclyde
        1
    julyclyde  
       Nov 14, 2013
    proxy_set_header是给后面服务器看的
    lfzyx
        2
    lfzyx  
    OP
       Nov 14, 2013
    @julyclyde 什么意思?那我有什么办法去看这个值获取了没有呢?
    julyclyde
        3
    julyclyde  
       Nov 14, 2013
    @lfzyx proxy_pass的目标,也就是那个http://xxx.com:8080的服务器才能看到这个header
    你这里是看不到的
    Kvm
        4
    Kvm  
       Nov 14, 2013
    [$http_x_real_ip]去掉

    $http_h1ost应该是$http_host
    lfzyx
        5
    lfzyx  
    OP
       Nov 14, 2013
    @Kvm 服务段我自定义了变量啊,不用nginx自带的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3325 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 11:16 · PVG 19:16 · LAX 04:16 · JFK 07:16
    ♥ Do have faith in what you're doing.