【问题标题】:Dockerized joomla site with Apache2 as proxy, problems loading .js files使用 Apache2 作为代理的 Dockerized joomla 站点,加载 .js 文件时出现问题
【发布时间】:2018-02-19 10:21:31
【问题描述】:

我正在将最初安装在一台服务器(比如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”.

问题似乎与 joomla 代码试图从 localhost 而不是 www.example.com 访问 javascript 文件有关,但我不知道如何解决这个问题。

正如我所写,如果我使用IP/PORT 访问浏览器(我的本地计算机与服务器在同一网络下,所以我可以直接从这里访问端口 8081)一切正常,访问时也正常旧服务器上的站点。

编辑:只是为了添加更多细节,不仅在我加载主页时样式被破坏,而且菜单链接现在指向http://localhost:8081/index.php/en/...page url...

【问题讨论】:

    标签: apache docker joomla


    【解决方案1】:

    尝试更改配置文件的底部:

        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 端口,我认为这可能是不可取的,所以请确保不会发生这种情况。

    【讨论】:

      猜你喜欢
      • 2021-07-09
      • 1970-01-01
      • 2010-12-31
      • 2023-02-10
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多