nginx upstream中带下划线bug,客户端会报400错误

现象

在本地可以获取前端header传的参数,但是部署到服务器获取的就是400(服务器地址用nginx做了代理)

原因

nginx 对http请求头字段做了限制,默认 underscores_in_headers 为off,表示如果header字段中包含下划线,则忽略掉,部署后就获取不到。

解决办法:

方法1:
在header里不要用 “_” 下划线,可以用驼峰命名或者中划线代替;

方法2:
在nginx里的 nginx.conf文件中配置http的部分添加 : underscores_in_headers on。

已标记关键词 清除标记
nginx作代理,相同的配置可以将请求转发到weblogic的7001端口,但是转发至8080端口报400错误;下面是配置文件和日志文件;即http://188.185.1.191:7001/是可以正常访问,但是http://188.185.1.191:8080无法正常访问,http://188.185.1.189:8080是可以正常访问;nginx安装在188.185.1.191服务器上; =========================配置文件========================= server { listen 7001; server_name localhost; location / { #allow 36.0.16.106; #deny all; proxy_redirect off; proxy_set_header Host $host:server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_pass http://188.185.1.189:7001/; } access_log logs/7002access.log; } server { listen 8080; server_name localhost; location / { proxy_redirect off; proxy_set_header Host $host:server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_buffering off; proxy_pass http://188.185.1.189:8080/; } access_log logs/8080access.log; } =======================日志文件============================​ 188.185.4.82 - - [02/Mar/2016:17:45:43 +0800] "\x03" 400 172 "-" "-" 188.185.4.82 - - [02/Mar/2016:19:11:06 +0800] "GET /index.jsp HTTP/1.1" 400 5 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER" 188.185.4.82 - - [02/Mar/2016:19:11:09 +0800] "GET /favicon.ico HTTP/1.1" 400 5 "http://188.185.1.191:8080/index.jsp" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER" 188.185.4.82 - - [02/Mar/2016:19:11:19 +0800] "GET /index.jsp HTTP/1.1" 400 5 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER" 188.185.4.82 - - [02/Mar/2016:19:11:20 +0800] "GET /favicon.ico HTTP/1.1" 400 5 "http://188.185.1.191:8080/index.jsp" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER"
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:设计师小姐姐 返回首页