Loading

Nginx反向代理导致请求header头信息丢失

背景:前端与后端调试接口,后端拿不到前段发过去的请求头信息,导致接口不通。(但是在本地是可以拿到的)

原因:nginx做了反向代理,没有请求时候加头信息的配置

报错如下:


解决方法:

方法一:NGINX代理时加上请求头信息:

location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://192.168.18.72/mkh5;
}

由于前端代码request的header中包含"_",所以这个配置没有生效

方法二:从根本解除nginx的限制,nginx默认request的header的那么中包含"_"时,会自动忽略掉。http部分中添加如下配置:

默认underscores_in_headers为off

underscores_in_headers on;
posted @ 2024-11-29 17:27  阿张Respect  阅读(857)  评论(0)    收藏  举报