2017-04-18 11 views
1

我有一個node + express網站在端口10000上運行在我的ubuntu服務器上,端口80上的nginx使用proxy_pass到localhost:10000。我的問題是,當我問快遞主機時,它會返回本地主機而不是我的域名。我使用nginx代理,以便我可以管理指向不同應用程序的計算機上的多個域。Node + Express + NGINX應用程序返回localhost而不是域

有沒有辦法在我的node + express服務器上保留原始主機名,同時仍然在nginx中使用proxy_pass?

回答

1

缺省情況下,nginx將上游請求中的主機頭設置爲出現在proxy_pass語句中的主機名。在這種情況下,localhost

您需要使用proxy_set_header指令明確設置主機頭。

例如,我總是將這個組:

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    ""; 

更多見this document

+0

先生,您是一位紳士和學者。 –

相關問題