2

In this answer

https://stackoverflow.com/a/5015178/2308693

the user Joao Da Silva showed what HTTP headers he forwards from nginx to Node.js.

How do you know what headers Node.js needs?

Are there any standards in the protocols about what headers are required, recommended, optional etc.?

Community
  • 1
  • 1
7cows
  • 4,974
  • 6
  • 25
  • 30
  • 1
    Why would you want to limit headers that are pass on? The default for nginx is to pass on all headers, supplemented by any headers you set with proxy_set_header (as demonstrated in the answer you cite). This works fine. – Myrne Stol Jun 01 '13 at 11:27
  • 1
    Actually when you say " user Joao Da Silva showed what HTTP headers he forwards from nginx to Node.js", this is incorrect. `proxy_set_header` sets (or changes) a header. All request headers are forwarded by default, unless you set `proxy_pass_request_headers` to `off`. – Myrne Stol Jun 01 '13 at 11:30
  • @MerynStol Thanks, that makes sense. But what's the purpose of it? Except for the custom "X-NginX-Proxy true" he uses, everything else is forwarded by default so what's the point? Feel free to put your comments in an answer. – 7cows Jun 01 '13 at 12:42
  • 1
    " everything else is forwarded by default" - I wasn't aware of that. Where is that documented? I see plenty examples on the web including it explicitly (include the answer you cite). I don't post an answer because I don't have experience using nginx as a proxy. :) – Myrne Stol Jun 01 '13 at 12:49
  • @MerynStol You said: "I wasn't aware of that. Where is that documented?" I thought that is what you said in an earlier comment! This is what you said earlier: "All request headers are forwarded by default, unless you set proxy_pass_request_headers to off." Hmm, some confusion here :) – 7cows Jun 01 '13 at 13:43
  • 1
    Eh, the original request headers, yes. Not `X-Real-IP`, `X-Forwarded-For`, which he explicitly sets. At first glance. the inclusion of `Host` seems superfluous, but according to [this article](http://www.simplicidade.org/notes/archives/2011/02/nginx_proxy_host_header.html) `Host` would be changed from its original value by nginx, so need to put back to get its usefulness for "virtual hosts" back. – Myrne Stol Jun 01 '13 at 13:48
  • 1
    Note that in principle, NONE of these headers are required for Node.js. It's not part of HTTP. It's included to have more insight (from inside code running on Node.js) into the original request that needs to be served. If you don't plan to read those headers at some point, you don't need to include them. – Myrne Stol Jun 01 '13 at 13:51
  • @MerynStol But what is the point of the X-Real-IP and X-Forwarded-For variables? Is it because $remote_addr and $proxy_add_x_forwarded_for will also be modified along the way, just like $http_host? – 7cows Jun 01 '13 at 16:10
  • @MerynStol Also, why did he use just Host and not X-Host? Is it maybe because some frameworks like Express rely on the Host header? (That's just a random guess of mine) – 7cows Jun 01 '13 at 16:11
  • 2
    X-Real-IP and X-Forwarded-For headers are just the way to send these variables (`$remote_addr` and `$proxy_add_x_forwarded_for`) to the Node.js process. These variables are local to nginx. Overriding the `Host` variable (in effect setting it back to its original value in the request) is done to make the request look as much as possible like a direct HTTP request. Something like `express.vhost` middleware makes indeed use of that. – Myrne Stol Jun 01 '13 at 20:02
  • @MerynStol Please summarize your wisdom in an answer dude (or simply write "see comments above" in the answer) so I can accept it and you can get some more points! :) – 7cows Jun 07 '13 at 08:09

0 Answers0