简体   繁体   中英

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

I am sending a request from my vue js app with header

{
   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"
}

When it gets to my digitalocean droplet, it goes through NGINX . On logging the request header at the node-express api, it shows another header format without the 'hotel_id' element, yet I really need that header element to continue with the appropriate functioning of the system. This is the request header logged at the 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'
}

It was working well on local computer before deploying.

After my research, I found out that underscores in headers do not make it through nginx, for this example it is 'hotel_id'. I needed to add

underscores_in_headers on;

in my nginx server block (context: http, server) since its default is

underscores_in_headers off;

For more information, follow this link https://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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