2016-11-26 52 views
0

我正在使用Debian和apache2,我不知道是否有可能使用apache將代理從一個域逆向轉換到另一個域,但後端服務器後面的後端服務器仍然認爲請求的URL是後者?如何設置Apache 2反向代理轉發不同的域名並假裝爲該域名?

例如,如果您訪問https://www.example.com/index.html,將請求轉發給https://www.example.org/index.html,但在www.example.org的後端服務器仍認爲請求URL是https://www.example.org/index.html,不https://www.example.com/index.html

我想我需要改變X-Forwarded-Server頭在Apache代理中,但我不知道如何。任何幫助將不勝感激。

回答

1

您所描述的行爲是默認行爲:

如果example.com具有以下配置:

ProxyPass/http://example.org/ 

我去http://example.com/,那麼example.org會看到下面的請求(檢查Host標題):

GET/HTTP/1.1 
Host: example.org 
[...] 
X-Forwarded-For: <client IP address> 
X-Forwarded-Host: example.com 

隨着ProxyPreserveHost On,你改變這種行爲,並得到

GET/HTTP/1.1 
Host: example.com 
[...] 
X-Forwarded-For: <client IP address> 
X-Forwarded-Host: example.com 

除非example.org使用X-Forwarded-Host頭決定哪些內容服務,你是好。

+0

謝謝。我再次測試,結果如下:Host = example.org,X-Forwarded-Host = example.com,X-Forwarded-Server = example.com – Ryan