nginx代理请求头header丢失以及请求头名称中下划线处理

tech2025-08-04  19

一:解决nginx代理 请求头header丢失

在nginx配置文件nginx.conf中找到代理配置,添加:如下的proxy_set_header配置

server { listen 1234; server_name localhost; location / { proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }

二:解决nginx代理 请求头名称中下划线

nginx代理后请求头header中的下划线默认会自动忽略掉

在nginx配置文件nginx.conf中的http配置中添加:underscores_in_headers on;

默认这个配置是关掉的,设置为on,就可以正常使用下划线作为分隔符了

最新回复(0)