【发布时间】:2018-03-06 01:11:36
【问题描述】:
我有 nodejs 和 nginx 正在运行,我在 API 'api_key' 中发送了一个额外的标头,它没有在 nodejs 中的 req.headers 和 req.get('api_key') 中收到我有下面的 nginx 配置文件
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
server_name mysite.com;
return 301 https://$host$request_uri;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:9102/;
proxy_set_header Host $http_host;
proxy_set_header api_key $http_api_key;
#proxy_set_header api_key 'Some Value'; works
proxy_redirect off;
}
}
如果设置proxy_set_header api_key 'some value' 的值,它会起作用并且标题会打印在控制台上,但api_key 会发生变化,这就是我使用$http_api_key 的原因,以便api_key 中的任何内容都被接收到自定义标题是从休息客户端发送的。我尝试了几种解决方案,例如proxy_set_header api_key $upstream_http_api_key;,但没有帮助。我想在 nodejs 中接收从 rest 客户端发送的任何自定义标头。
【问题讨论】:
-
添加
proxy_pass_header api_key;,不要自己设置。看看有没有帮助
标签: node.js nginx http-headers reverse-proxy nginx-reverse-proxy