使用 nginx 建立企業傘網站

使用 nginx 建立企業傘網站

我的客戶要求將他所有的企業合併到一把傘中,而不將它們從原來的位置移除。例如,他已經有一個以realestate.com 和movers.com 身份運行的網站,現在他希望將它們合併到Corporate.com 下,這樣Corporate.com/real 連結將映射到real.corporate.com 並顯示託管在以下地點的網站:房地產網。這不是重定向,因此 URL 欄將顯示 real.corporate.com for realestate.com,所有連結也將是相對的,例如 realestate.com/index.html 將顯示為 real.corporate.com/index.html。 realestate.com/portfolio/houses/pictures 將變為 real.corporate.com/portfolio/houses/pictures。我嘗試過使用 proxy_pass 但這會更改 URL。我目前正在一個站點上進行測試,以下是我的伺服器區塊

server{
listen 80;

location / {
proxy_pass http://www.realestate.com/;
sub_filter_once off;
proxy_redirect off;
proxy_set_header Host $host;
}
}

此設定直接將我帶到 realestate.com,瀏覽器中的 URL 也發生了更改。更改位置會location /real出現 404 錯誤。

請幫忙

答案1

您的配置不執行任何重定向。重定向由位於 的上游網路伺服器發送realestate.com

應用程式發送重定向到realestate.com,因為請求未發送到應用程式中配置的網域。

您可以使用以下方法變更此設置

proxy_set_header Host www.realestate.com;

此設定發送帶有標頭的上游代理請求Host: www.realestate.com,這將使其最終到達上游伺服器中的正確虛擬伺服器。

但是,您仍然可能遇到由 產生的連結的問題www.realestate.com

此外,如果www.realestate.com發送任何 HTTP 重定向,您需要將重定向內容替換為proxy_redirect default;指令。

相關內容