原文地址:http://313968.blog.51cto.com/303968/895672
使用nginx做负载均衡或http代理时,碰到http header不转发的问题。
配置里只有转发设置原始ip和host的
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Server $host;
但我自定义的header却都忽略掉了。百思不得其解:
1、理论上转发header是基本功能啊,apache都没问题
2、网上也搜不到此类问题说明
3、可能大家都不用客户端自定义提交header?
打开nginx的debug:
配置中:
daemon off;
error_log logs/error.log debug;
看error_log
发现解析header时出现:
2010/12/13 18:49:06 [info] 6248#1476: *1 client sent invalid header line: “wiz_api_version: 2″ while reading client request headers, client: 223.254.100.103, server: localhost, request: “POST /wizkm/a/upload HTTP/1.1″
明显是忽略掉了我自定义的header。
差点绝望。还好开源软件可以看源码。
找出个所以然,果然被我找到问题了:
rc = ngx_http_parse_header_line(r, r->header_in, cscf->underscores_in_headers);
if (r->invalid_header && cscf->ignore_invalid_headers)
在ngx_http_parse_header_line() 函数中
if (ch == ‘_’) {
if (allow_underscores)
else
红色部分就是问题所在了
原来是对header name的字符做了限制,默认 underscores_in_headers 为off,表示如果header name中包含下划线,则忽略掉。
恰好我自定义的header中都是用的下划线。
处理办法:
1:配置中http部分 增加underscores_in_headers on; 配置
2:用减号-替代下划线符号_,避免这种变态问题。nginx默认忽略掉下划线可能有些原因。
相关推荐
nginx 版本 1.11.3 使用大家说的以下配置,验证无效,跨域问题仍然存在 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow...
开发网关项目时,在请求时往请求头header中放入了签名sign_key信息,在接收请求时再从header中拿出,在本地调试时是可以的,但上线之后通过Nginx代理之后发现拿不到。 location / { proxy_set_header X-Real-IP $...
(a)客户端首次发起访问请求,nginx接收后,发现请求头没有cookie,则以轮询方式将请求分发给后端服务器。 (b)后端服务器处理完请求,将响应数据返回给nginx。 (c)此时nginx生成带route的cookie,返回给...
Nginx 配置TCP代理转发 使用Nginx 新版的 stream方式,实现TCP/UDP代理转发。
用Nginx向http request请求的http header中添加字段
windows平台nginx编译nginx-http-flv-module,可直接运行,基于nginx-1.17.10编译
在windows 7 64位 环境下使用nginx的nginx-http-flv-module搭建flv视频流播放所有的安装包,参考:https://blog.csdn.net/qq_33071429/article/details/102628008
nginx sticky是nginx的module,可以实现基于cookie的负载均衡。 下载后,在编译安装nginx时,用--add-module选项,指到sticky所在目录。类似命令如下: ./configure --prefix=/usr/local/nginx-1.6.0 --add-module=...
--> nginx-1.21.6 ======================== 在网上查找半天都只有教程,没有可免费下载的版本,深知没有积分遍地找资源的痛苦,无奈之下只好自己按照教程一步一个坑编译出来的,供大家免费下载使用。(无毒放心使用...
title: nginx解决Too-many-header问题在对接海康卫视WEB无插件开发包时,自己的页面连接单独的摄像头时(连接NVR没这个问题),/ISA
nginx + header 转发 灰度测试
gridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-nginx-plugingridfs-...
nginx + nginx-http-flv-module-1.2.9
Notepad++ ==>>> 语言 ==>>> 自定义语言格式 ==>>>导入
但问题来了,nginx在会话保持这方面比较弱,用ip_hash做会话保持有很大的缺陷,它是通过客户端ip来实现,根据访问ip的hash结果分配请求到后端的app服务器,负载不会很均匀。之前在一个小项目前中使用过这种方法,...
nginx-upstream-jvm-route 支持nginx版本1.15 解决nginx: [emerg] invalid parameter "srun_id=tomcat1" 问题
基于nginx1.19.3版本,已编译好nginx-http-flv-module,开箱即用。鄙视那些收C币的。
nginx-rtmp模块源码包nginx-rtmp-module-master
nginx-http-flv-module-master, 因为RTMP,HLS 都会存在这样那样的缺点,为了更好的解决延时问题、拉流兼容性问题,所以我们准备用flv.js 进行拉流。 对应的nginx组件