Apache ProxyPass 缺少图像

Apache ProxyPass 缺少图像

我的 glassfish 服务器前面有一个 apache 服务器。mydomain.com 直接转到我在 apache 上的静态文件,然后如果您点击子域 forum.mydomain.com,它会转到 127.0.0.1:8080/forum/ 上的 glassfish webapp forum/。这个代理似乎可以工作,它会带我进入 web 应用程序,但所有图像都丢失了!下面是我设置虚拟主机的方法。

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias subdomain.mydomain.com mydomain.com
    DocumentRoot "/usr/local/apache/htdocs"

</VirtualHost>


<VirtualHost *:80>
    ServerName forum.mydomain.com
    # any logging config, etc, that you need
    ProxyPass / http://127.0.0.1:8080/forum/
    ProxyPassReverse / http://127.0.0.1:8080/forum/
</VirtualHost>

在访问日志中我看到的就是这些。

[15/Jan/2012:03:28:02 +0000] "GET /forums/list.page HTTP/1.1" 200 12861
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/logo.jpg HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/styles/style.css?1326582403934 HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/icon_mini_recentTopics.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/icon_mini_search.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/icon_mini_members.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/styles/en_US.css?1326582403934 HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/icon_mini_groups.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/folder_big.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/icon_mini_login.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/whosonline.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/icon_mini_register.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/ping_session.jsp HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/folder_lock.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/folder.gif HTTP/1.1" 404 1075
[15/Jan/2012:03:28:02 +0000] "GET /forum/templates/default/images/folder_new.gif HTTP/1.1" 404 1075

知道为什么图像无法正常工作吗?

答案1

论坛代码将/forum/路径硬编码在发送给客户端的 HTML 中,或者在其配置中的某个位置进行定义。如果您可以将其更改为/,请这样做;否则,您可以在 Apache 配置中解决这个问题:

<VirtualHost *:80>
    ServerName forum.mydomain.com
    ProxyPass /forum/ http://127.0.0.1:8080/forum/
    ProxyPassReverse /forum/ http://127.0.0.1:8080/forum/
    ProxyPass / http://127.0.0.1:8080/forum/
    ProxyPassReverse / http://127.0.0.1:8080/forum/
</VirtualHost>

答案2

您可以通过将重写引擎放置在虚拟主机中来修复此问题。

RewriteEngine on
RewriteRule ^/forum/(images|javascripts|stylesheets)(.*) /forum/$1$2

更多详细信息请参阅这里用于重写引擎

答案3

根据@Mughil 的回答,我创建了以下内容以帮助我将其用于所有网站。

RewriteEngine on
RewriteRule ^/(.*)/(images|javascripts|stylesheets)(.*) /$1/$2$3

相关内容