1

I'm using nginx to proxy my nodejs app. In my app, I always asking a "client_id" from header. When I'm doing the local test. Everything working correct. But when I push to server and proxy by Nginx. Then the client_id lost. I can see that when nginx do the proxy, it remove my custom header "client_id".

What I want to ask is:

  1. is there a way to make sure nginx can pass my client_id to nodejs?
  2. is there a way can make nginx pass whatever the custom headers?

2 Answers 2

5

Thanks @Peter Lyons, I just found the reason. Yes, nginx do pass all headers to the destination server as default. But, the exception is, as default, nginx block all headers which the name contain an underscore "_".

I don't know why nginx do this. But in this question, this underscore thing is the reason that I can't get my header "client_id".

There are 2 way to solve it:

1, change the header name to avoid the underscore, in this question, change "client_id" to "clientId" or "client-id"

2, in nginx.conf, inside http part, set underscores_in_headers on;, for example:

http {
    ....

    underscores_in_headers on;

    ....
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you :) But any reason for this ?
0

by default, nginx's HttpProxyModule has proxy_pass_request_headers enabled, and thus will pass on the client request headers to the destination server.

My first suggestions is to try renaming your header to "X-Client-Id" to utilize the extension namespace HTTP has reserved for non-standard headers such as yours and see if nginx will forward that. If not, have a look at the proxy_set_header directive.

Side note: using a custom header at all, and specifically one called "client_id" is almost a sure sign you are reinventing the wheel or don't understand industry standards for using cookies and sessions. Unless you are really sure you need this, you may want to step back and rethink your underlying problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.