繁体   English   中英

如何让我的所有标题元素通过 nginx 到达我的节点 js api

[英]How can I make all my header elements to go through nginx to my node js api

我正在从我的 vue js 应用程序发送一个带有标题的请求

{
   Access-Control-Allow-Headers: "Origin, Content-Type, X-Auth-Token"
   Access-Control-Allow-Methods: "GET, POST, PATCH, PUT, DELETE, OPTIONS"
   Access-Control-Allow-Origin: "*"
   hotel_id: "custom-hotel-id-value-here"
   token: "custom-token-value-here"
}

当它到达我的 digitalocean droplet 时,它会通过NGINX 在 node-express api 上记录请求标头时,它显示了另一种没有“hotel_id”元素的标头格式,但我确实需要该标头元素来继续系统的适当功能。 这是在 node-express api 记录的请求头

{
   'x-real-ip': '197.157.*.*',
   'x-forwarded-for': '197.157.*.*',
   'x-nginx-proxy': 'true',
   host: '206.189.*.*:*',
   connection: 'close',
   'access-control-allow-origin': '*',
   'access-control-allow-headers': 'Origin, Content-Type, X-Auth-Token',
   'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
   token: 'custom-token-value-here'
   'access-control-allow-methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
   accept: '*/*',
   origin: 'http://206.189.*.*',
   referer: 'http://206.189.*.*/',
   'accept-encoding': 'gzip, deflate',
   'accept-language': 'en-US,en;q=0.9'
}

在部署之前,它在本地计算机上运行良好。

经过我的研究,我发现标头中的下划线不能通过 nginx,在这个例子中它是 'hotel_id'。 我需要添加

underscores_in_headers on;

在我的 nginx 服务器块(上下文:http,服务器)中,因为它的默认值是

underscores_in_headers off;

有关更多信息,请点击此链接https://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM