使用 Apache2 作为代理的 Dockerized joomla 站点,加载 .js 文件时出现问题
Dockerized joomla site with Apache2 as proxy, problems loading .js files
我正在将最初安装在一台服务器(比如 SERVER_1
)下的 joomla 网站作为 Apache 2 下的 Web 应用程序移动到另一台服务器(SERVER_2
)。
在第二台服务器中,joomla 站点安装为 docker 容器(实际上是两个 docker 容器,第二个 运行 一个 mysql 实例)。 joomla contiainer 公开了端口 8081
,如果我通过浏览器 http://<SERVER_2_IP>:8081/
访问,该网站将完美运行。
现在,我尝试将名称 www.example.com
的提供商的 DNS 设置从旧服务器的 IP 更改为新服务器的 IP。此外,在 SERVER_2
上我有一个 apache2 用作代理,将请求转发到 www.example.com
到正确的端口 8081。以下是 apache2 的虚拟主机定义文件(我不是apache2 配置专家,只是将此从配置映射复制到其他容器化应用程序,非 joomla 应用程序,工作正常)。
<VirtualHost *:80>
ServerName www.example.com
<LocationMatch "^/">
AllowOverride None
Require all granted
</LocationMatch>
ErrorLog /path/to/folder/under/home/example.error.log
LogLevel trace1
CustomLog /path/to/folder/under/home/example.access.log combined
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
</VirtualHost>
问题是,在 http://www.example.com
从浏览器访问网站时,虽然找到了网站,但似乎样式已损坏。如果我检查浏览器控制台,我会看到如下错误列表(注意:我从意大利语翻译了这条消息,所以实际的错误消息可能不同)。
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/jquery.min.js”.
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/jquery-noconflict.js”.
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/jquery-migrate.min.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/caption.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/mootools-core.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/core.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/mootools-more.js”.
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/bootstrap.min.js”.
Loading failed for the <script> with source “http://localhost:8081/templates/whalesafe/javascript/md_stylechanger.js”.
Loading failed for the <script> with source “http://localhost:8081/templates/whalesafe/javascript/hide.js”.
Loading failed for the <script> with source “http://localhost:8081/templates/whalesafe/javascript/respond.src.js”.
Loading failed for the <script> with source “http://localhost:8081/media/sourcecoast/js/jq-bootstrap-1.8.3.js”.
问题似乎与试图从 localhost
而不是 www.example.com
访问 javascript 文件的 joomla 代码有关,但我不知道如何解决这个问题。
如我所写,如果我使用 IP/PORT
访问浏览器(我的本地机器与服务器在同一网络下,因此我可以直接从这里访问端口 8081)一切正常,因为在旧服务器上访问网站时正常。
edit: 只是为了添加更多的细节,当我加载主页时不仅样式被破坏,而且菜单链接现在指向 http://localhost:8081/index.php/en/...page url...
尝试更改配置文件的底部:
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
到
ProxyPreserveHost On
ProxyPass / http://www.example.com:8080/
ProxyPassReverse / http://www.example.com:8080/
还要确保您通过 http 而不是 https 请求所有资源,因为这两种协议需要一个单独的端口。
这应该会立即解决;但请考虑将您的容器也设置为转发 https 流量,并将您的站点移动到 https。
此外,这些指令应该由 mod_proxy 处理,也许您的代理并没有像您期望的那样真正工作(它正在进行重定向而不是代理),所以用户看到 8081 端口,我认为这可能是不可取的,因此请确保不会发生这种情况。
我正在将最初安装在一台服务器(比如 SERVER_1
)下的 joomla 网站作为 Apache 2 下的 Web 应用程序移动到另一台服务器(SERVER_2
)。
在第二台服务器中,joomla 站点安装为 docker 容器(实际上是两个 docker 容器,第二个 运行 一个 mysql 实例)。 joomla contiainer 公开了端口 8081
,如果我通过浏览器 http://<SERVER_2_IP>:8081/
访问,该网站将完美运行。
现在,我尝试将名称 www.example.com
的提供商的 DNS 设置从旧服务器的 IP 更改为新服务器的 IP。此外,在 SERVER_2
上我有一个 apache2 用作代理,将请求转发到 www.example.com
到正确的端口 8081。以下是 apache2 的虚拟主机定义文件(我不是apache2 配置专家,只是将此从配置映射复制到其他容器化应用程序,非 joomla 应用程序,工作正常)。
<VirtualHost *:80>
ServerName www.example.com
<LocationMatch "^/">
AllowOverride None
Require all granted
</LocationMatch>
ErrorLog /path/to/folder/under/home/example.error.log
LogLevel trace1
CustomLog /path/to/folder/under/home/example.access.log combined
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
</VirtualHost>
问题是,在 http://www.example.com
从浏览器访问网站时,虽然找到了网站,但似乎样式已损坏。如果我检查浏览器控制台,我会看到如下错误列表(注意:我从意大利语翻译了这条消息,所以实际的错误消息可能不同)。
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/jquery.min.js”.
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/jquery-noconflict.js”.
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/jquery-migrate.min.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/caption.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/mootools-core.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/core.js”.
Loading failed for the <script> with source “http://localhost:8081/media/system/js/mootools-more.js”.
Loading failed for the <script> with source “http://localhost:8081/media/jui/js/bootstrap.min.js”.
Loading failed for the <script> with source “http://localhost:8081/templates/whalesafe/javascript/md_stylechanger.js”.
Loading failed for the <script> with source “http://localhost:8081/templates/whalesafe/javascript/hide.js”.
Loading failed for the <script> with source “http://localhost:8081/templates/whalesafe/javascript/respond.src.js”.
Loading failed for the <script> with source “http://localhost:8081/media/sourcecoast/js/jq-bootstrap-1.8.3.js”.
问题似乎与试图从 localhost
而不是 www.example.com
访问 javascript 文件的 joomla 代码有关,但我不知道如何解决这个问题。
如我所写,如果我使用 IP/PORT
访问浏览器(我的本地机器与服务器在同一网络下,因此我可以直接从这里访问端口 8081)一切正常,因为在旧服务器上访问网站时正常。
edit: 只是为了添加更多的细节,当我加载主页时不仅样式被破坏,而且菜单链接现在指向 http://localhost:8081/index.php/en/...page url...
尝试更改配置文件的底部:
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
到
ProxyPreserveHost On
ProxyPass / http://www.example.com:8080/
ProxyPassReverse / http://www.example.com:8080/
还要确保您通过 http 而不是 https 请求所有资源,因为这两种协议需要一个单独的端口。
这应该会立即解决;但请考虑将您的容器也设置为转发 https 流量,并将您的站点移动到 https。
此外,这些指令应该由 mod_proxy 处理,也许您的代理并没有像您期望的那样真正工作(它正在进行重定向而不是代理),所以用户看到 8081 端口,我认为这可能是不可取的,因此请确保不会发生这种情况。