Apache-2.4
使用 mod_proxy 時出現許多 404 URLH時間__H噸米l_html
我想做的事
使所有http://cloud.example.com/>顯示為<http://webmail.example.com/cloud/
- http://cloud.example.com:目標網站
- http://webmail.example.com:使用 mod_proxy 執行 apache2 的網站,作為反向代理(但不僅限於,還有 webmail)。
- http://webmail.example.com/cloud>:我希望<http://cloud.example.com出現的 URL。
我是如何嘗試做到的
<VirtualHost *:80> ServerName webmail.example.com DocumentRoot /var/www/roundcubemail-1.1.4 Loglevel debug ErrorLog /var/log/apache2/roundcube.error # %t : Time # %a : client ip # %f : filename # %T : processing time # %s : status # %>s : Final status LogFormat "%t %a %{Referer}i -> %U%q, matches %f, %s>%>s(served in %{ms}T µs)" custom # was "combined" CustomLog /var/log/apache2/roundcube.access custom ProxyPass "/cloud/" "http://cloud.example.com/" ProxyPassReverse "/cloud/" "http://cloud.example.com/" # The ProxyRequests directive should usually be set off when using ProxyPass. # src:https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass ProxyRequests off # https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypreservehost # This option should normally be turned Off. ProxyPreserveHost off </VirtualHost>
日誌
[14/Jun/2016:13:42:37 +0100] 192.168.211.202 - -> /cloud/, matches proxy:http://cloud.example.com/, 200>200(served in 5 µs) [14/Jun/2016:13:42:42 +0100] 192.168.211.202 - -> /core/css/styles.css?v=9a1b1350ff46cbc098bc6c7acca55c1c, matches /var/www/roundcubemail-1.1.4/core, 404>404(served in 0 µs) [14/Jun/2016:13:42:42 +0100] 192.168.211.202 - -> /core/css/header.css?v=9a1b1350ff46cbc098bc6c7acca55c1c, matches /var/www/roundcubemail-1.1.4/core, 404>404(served in 0 µs) [14/Jun/2016:13:42:42 +0100] 192.168.211.202 - -> /core/css/mobile.css?v=9a1b1350ff46cbc098bc6c7acca55c1c, matches /var/www/roundcubemail-1.1.4/core, 404>404(served in 0 µs) [14/Jun/2016:13:42:42 +0100] 192.168.211.202 - -> /core/css/icons.css?v=9a1b1350ff46cbc098bc6c7acca55c1c, matches /var/www/roundcubemail-1.1.4/core, 404>404(served in 0 µs) [14/Jun/2016:13:42:42 +0100] 192.168.211.202 - -> /core/css/fonts.css?v=9a1b1350ff46cbc098bc6c7acca55c1c, matches /var/www/roundcubemail-1.1.4/core, 404>404(served in 0 µs) [14/Jun/2016:13:42:42 +0100] 192.168.211.202 - -> /core/css/apps.css?v=9a1b1350ff46cbc098bc6c7acca55c1c, matches /var/www/roundcubemail-1.1.4/core, 404>404(served in 0 µs) ...
日誌的第一行顯示請求“/cloud/”路徑成功從代理網站檢索資源,但所有後續資源都不是從雲伺服器獲取,而是從網路郵件伺服器本身獲取。
我該如何處理?
我啟用了 proxy_html。
root@messagerie[CHROOT][10.10.10.20] ~ # a2query -m proxy (enabled by site administrator) php5 (enabled by maintainer script) setenvif (enabled by maintainer script) ssl (enabled by site administrator) deflate (enabled by maintainer script) authn_core (enabled by maintainer script) env (enabled by maintainer script) mime (enabled by maintainer script) auth_basic (enabled by maintainer script) access_compat (enabled by maintainer script) authz_core (enabled by maintainer script) xml2enc (enabled by site administrator) authz_host (enabled by maintainer script) alias (enabled by maintainer script) authz_user (enabled by maintainer script) autoindex (enabled by maintainer script) negotiation (enabled by maintainer script) socache_shmcb (enabled by site administrator) proxy_http (enabled by site administrator) status (enabled by maintainer script) proxy_html (enabled by site administrator) filter (enabled by maintainer script) authn_file (enabled by maintainer script) dir (enabled by maintainer script) mpm_prefork (enabled by maintainer script) root@messagerie[CHROOT][10.10.10.20] ~ #
正如@HBrijn 所建議的那樣,我添加了
ProxyPass "/core/" "http://cloud.algerian-radio.dz/core/" ProxyPassReverse "/core/" "http://cloud.algerian-radio.dz/core/"
但是隨後伺服器收到了對 /index.php/apps/files/ 的請求,所以我也添加了它
ProxyPass "/index.php/apps/files/" "http://cloud.algerian-radio.dz/apps/file\ s/" ProxyPassReverse "/index.php/apps/files/" "http://cloud.algerian-radio.dz/app\ s/files/"
擺脫了所有 404 錯誤,但仍然無法讓 owncloud 工作。
http://webmail.example.com/cloud>重定向到<http://webmail.example.com/index.php/apps/files/顯示這個不錯的錯誤:
Fatal error: Class 'OCP\User' not found in /usr/local/nginx/html/owncloud/apps/files/index.php on line 33
編輯:固定!,owncloud 方面需要一些額外的配置,即trusted_proxies和overwritewebroot。