PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

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

 September 01, 2022     express, nginx, nginx-reverse-proxy, node.js, request-headers     No comments   

Issue

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.


Solution

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



Answered By - Ian Mawanda
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing