nginx转发丢失请求头

一、服务端配置缺少

server{

....

  location{

    ##重写请求头host字段、来源ip、端口以及请求地址

    proxy_set_header Host $host;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Real-PORT $remote_port;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

  }

}

二、nginx配置缺少

http{

  ##默认为off

  underscores_in_headers on;

}

三、官方解释

Syntax: underscores_in_headers on | off;
Default: underscores_in_headers off;
Context: http, server

Enables or disables the use of underscores in client request header fields. When
the use of underscores is disabled, request header fields whose names contain underscores
are marked as invalid and become subject to the ignore_invalid_headers directive.

由官方解释可以看出,默认情况下,underscores_in_headers为off,表示当客户端请求头中带有下划线的字段默认将会被标识为无效字段。

posted @ 2022-09-29 17:06  重生之我是java程序员  阅读(411)  评论(0编辑  收藏  举报