
我的 apache 反向代理出現一些錯誤。目前我正在對 4 個網站進行反向代理。
- 1.1.1.1/a
- 1.1.1.2/b
- 1.1.1.3/c
- 1.1.1.4/天
當反向代理到 a 和 b 網站時,我沒有任何問題。圖像很好,沒有問題。
然而,當談到c和d網站時。圖像未載入。
- - [08/May/2014:10:40:36 +0800] "GET /whatshot_v3/images/promo/img_samplePromo.jpg HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/menu/faq_butt_03.png HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/banner/text_planprice.gif HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/banner/text_services.gif HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/banner/text_account.gif HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/shortcut/bann_store.gif HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/shortcut/bann_rewards.gif HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/shortcut/bann_idd.gif HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/footer/img_customerService.png HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/footer/icon_fb.png HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/footer/icon_tw.png HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/footer/icon_rss.png HTTP/1.1" 404 1245
- - [08/May/2014:10:40:36 +0800] "GET /images_v3/footer/icon_share.png HTTP/1.1" 404 1245
從apache反向代理伺服器本身存取沒有問題。當從外部存取時,就會出現問題。
我嘗試在另一台機器上直接輸入網址並載入圖像。
1.1.1.1 - - [08/May/2014:10:19:00 +0800] "GET **/d/images_v3/footer/icon_share.png** HTTP/1.1" 200 869 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
1.1.1.1 - - [08/May/2014:10:18:24 +0800] "GET **/images_v3/footer/icon_share.png HTTP/1.1" 404 1245** "htt://1.2.3.4/digi/landing.do" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
正如您所看到的,第一個連結中的連結有效。第二個中的那個不是。
當我正常請求網頁時,它會請求第二個鏈接,會導致404錯誤,找不到路徑。
如果我直接輸入第一個鏈接,就會找到圖像。
我注意到當輸入連結時,c 和 d 網站被重定向。
1.1.1.3/c --> 1.1.1.3/c/index_other.html
1.1.1.4/d --> 1.1.1.4/d/landing.do
這是我的 apache 反向代理配置
<VirtualHost *:80>
#ServerAdmin [email protected]
#DocumentRoot /www/docs/dummy-host.example.com
#ServerName dummy-host.example.com
ErrorLog logs/arp_error_log
CustomLog logs/arp_access_log common
ProxyRequests Off
<Location /a>
ProxyPass http://1.1.1.1/a
ProxyPassReverse http://1.1.1.1/a
</Location>
<Location /b>
ProxyPass http://1.1.1.2/b
ProxyPassReverse http://1.1.1.2/b
</Location>
<Location /c>
ProxyPass http://1.1.1.3/index_other.html
ProxyPassReverse http://1.1.1.3/index_other.html
</Location>
<Location /d>
ProxyPass http://1.1.1.4:8080
ProxyPassReverse http://1.1.1.4:8080
</Location>
</VirtualHost>
那麼,我該如何解決這個問題呢?我一直在研究 mod_rewrite 和 mod_proxy_html ,但沒有解決問題。
答案1
您可以為影像使用單獨的位置容器。
我沒有測試這個,但或多或少應該是這樣。
對於/c:
<Location /c/images_v3>
ProxyPass http://1.1.1.3/images_v3
ProxyPassReverse http://1.1.1.3/images_v3
</Location>
<Location /c>
ProxyPass http://1.1.1.3/index_other.html
ProxyPassReverse http://1.1.1.3/index_other.html
</Location>
對於 /d 我不太確定發生了什麼,也許 1.1.1.4:8080 上有一個重定向,將所有內容重定向到 /landing.do ?在這種情況下,以下內容將無濟於事:
<Location /d/images_v3>
ProxyPass http://1.1.1.4:8080/images_v3
ProxyPassReverse http://1.1.1.4:8080/images_v3
</Location>
<Location /d>
ProxyPass http://1.1.1.4:8080
ProxyPassReverse http://1.1.1.4:8080
</Location>