2013-01-20 44 views
1

我必須運行apache web服務器。一個在端口80上,另一個在端口8077上。將Apache mod重寫爲從一臺服務器指向另一臺

我想嘗試通過端口80的版本重定向所有流量,如果可能的話。

什麼,我想最好是能去http://translate.example.com ,交通得到指向http://www.example.com:8077

我已經得到了很多的mod_rewrite在主要港口80服務器怎麼回事,但我我不確定哪些服務器需要配置,或者兩者都需要配置。

我想確保translate.example.com/img(或任何其他子目錄)實際上指向8087/images目錄。

更新

我現在得到以下幾點:

RewriteCond %{HTTP_HOST} example[NC] 
RewriteCond %{REQUEST_URI} ^/glot$ [NC] 
RewriteRule ^(.*)$ http://www.example.com:8077/$1 [P] 
ProxyPassReverse/http://www.example.com/ 

我越來越看到其他的服務器新的頁面,但我發現所有的資源都沒有找到像圖片,CSS等

否則在安裝產品的所有資源都設置與領先的斜線查看源

例如

/img/glotpress-logo.png 

所以我不知道如何獲得資源加載。 注意如果原始起點爲www.example.com/glot而不是glot.example.com,原始問題

回答

1

您可以重新映射你的資源到另一臺服務器,但其在非默認端口的其他服務器可能會阻止某些訪問者從觀看他們,因爲他們可能是塊(防火牆)從訪問端口。如果你不擔心端口被阻塞,你可以使用mod_rewrite Remapping Resources.方法。

RewriteEngine On 
RewriteRule ^/images/(.+) http://www.example.com:8077/images/$1 [R,L] 

如果你想確保每個人都能夠查看外部資源,你需要使用代理那裏Apache將隧道訪問者連接到透明example.com:8077。你可以在apache網站上閱讀關於mod_rewrite for Proxying的更多信息。

RewriteEngine on 
RewriteBase /images/ 
RewriteRule ^images/(.*)$ http://example.com:8077/images/$1 [P] 
ProxyPassReverse /images/ http://example.com/images/ 

UPDATE

你有沒有試圖刪除

RewriteCond %{HTTP_HOST} example[NC] 

此行主要是告訴它只會過程如果從www.example未來如果HTTP_POST是example.com。 com此規則不適用。我希望「例子[NC]」是一個錯字。

在它可能看起來像

RewriteRule ^/glot/(.*)$ http://www.example.com:8077/glot/$1 [P] 
ProxyPassReverse /glot/ http://www.example.com:8077/glot/ 
+0

感謝年底,我現在已經更新了最初的問題跟進 – Andrew

+0

你有沒有試圖刪除 的RewriteCond%{HTTP_HOST}例如[NC] 這如果HTTP_POST來自http://www.example.com/,則該規則不適用。我希望「例子[NC]」是一個錯字。 最終它看起來像 RewriteRule ^/glot /(.*)$ http://www.example.com:8077/glot/$1 [P] ProxyPassReverse/glot/http://www.example .COM:8077/glot / –

相關問題