Apache-2.4

Apache Web 伺服器代理傳遞並在目標中獲取原始請求伺服器名稱

  • October 13, 2020

再會,

我的流程如下:

(public ip) 192.168.0.142 --> (192.168.111.66) web server --> (192.168.1.199) java web app server

在我的 192.168.111.66 Apache Web 伺服器中,我在 httpd.conf 中配置了以下內容:

ProxyPass "/image.web" "https://192.168.1.199/image.web"
ProxyPassReverse "/image.web" "https://192.168.1.199/image.web"

網路成功連接到我的 Web 應用程序伺服器(192.168.1.199),但是,在我的 Java Web 應用程序中,我看到請求是伺服器名稱為 192.168.1.199,我相信這是因為我在 Apache Web 伺服器中的配置,我可以知道我該如何配置,以便在我的 java web 應用程序中,我可以檢測到請求 servername 是 192.168.0.142,這是公共 ip。

剛剛找到答案:

ProxyPreserveHost On

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypreservehost

引用自:https://serverfault.com/questions/1038485