首页 > 服务器    日期:2019-02-08 / 来自互联网 / 浏览

开发网关项目时,在请求时往请求头header中放入了签名sign_key信息,在接收请求时再从header中拿出,在本地调试时是可以的,但上线之后通过Nginx代理之后发现拿不到。

location / {
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Host $http_host;
 proxy_set_header X-Nginx-Proxy true;
 
 add_header Proxy-Node $upstream_addr;
 add_header Proxy-Status $upstream_status; 
  
 proxy_http_version 1.1;
 proxy_pass http://tianusa;
 }

后来找到原因是因为Nginx对header有所限制,下划线(_)不支持

解决方法:

1.不用下划线 

把下划线_改成其他的,如sign_key改成sign-key

2.从根本解除Nginx的限制 

Nginx默认request的header的那么中包含'_'时,会自动忽略掉。

解决方法是:在nginx里的nginx.conf配置文件中的http部分中添加如下配置:

underscores_in_headers on; (默认 underscores_in_headers 为off)

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章