Node + Express + NGINX应用程序返回本地主机而不是域 [英] Node+Express+NGINX application returning localhost instead of domain

查看:29
本文介绍了Node + Express + NGINX应用程序返回本地主机而不是域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ubuntu服务器上的node + express网站在端口10000上运行,nginx在端口80上运行,使用proxy_pass到localhost:10000.我的问题是,当我要求主机作为快递时,它返回localhost而不是我的域名.我使用nginx代理,因此可以在计算机上管理指向不同应用程序的多个域.

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.

有没有办法在nginx中仍然使用proxy_pass的同时将原始主机名保留在我的node + express服务器上?

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

推荐答案

默认情况下, nginx 将上游请求中的Host标头设置为出现在 proxy_pass 中的主机名陈述.在这种情况下, localhost .

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

您需要使用 proxy_set_header 指令显式设置Host标头.

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.

这篇关于Node + Express + NGINX应用程序返回本地主机而不是域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆