Node+Express+NGINX application returning localhost instead of domain

ⅰ亾dé卋堺 提交于 2021-02-05 08:33:07

问题


I have a node+express website running on my ubuntu server on port 10000 with nginx on port 80 using a proxy_pass to localhost:10000. My issue is that when I ask for the host in express it returns localhost instead of my domain name. I use the nginx proxy so I can manage several domains on the machine pointing to different applications.

Is there a way to keep the original host name on my node+express server while still using proxy_pass in nginx?


回答1:


By default, nginx sets the Host header in the upstream request to the hostname appearing in the proxy_pass statement. In this case localhost.

You need to set the Host header explicitly using the proxy_set_header directive.

For example, I always set this group:

proxy_set_header  Host               $host;
proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
proxy_set_header  X-Forwarded-Proto  $scheme;
proxy_set_header  Accept-Encoding    "";
proxy_set_header  Proxy              "";

See this document for more.



来源:https://stackoverflow.com/questions/43478436/nodeexpressnginx-application-returning-localhost-instead-of-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!