首页 > 解决方案 > 反向代理 apache2 后面的 Mattermost docker 重定向错误

问题描述

我正在尝试使用 apache2 版本 2.4.7 在我的 Ubuntu 14.04 上安装 Mattermost 的 docker 版本。

这里是配置mattermost-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        ServerName www.my.website.fr
        ServerAlias website.fr
        DocumentRoot /home/www/www-website
  [...]
    <Proxy *>
        Require all granted
    </Proxy>
    ProxyPreserveHost On
    ProxyRequests Off
    RewriteEngine  on

    ProxyPass /mattermost http://localhost:8083
    ProxyPassReverse /mattermost http://localhost:8083

    RewriteCond %{REQUEST_URI} /api/v[0-9]+/(users/)?websocket [NC,OR]
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
    RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
    RewriteRule .* ws://127.0.0.1:8083%{REQUEST_URI} [P,QSA,L]

    <Location /home/www/www-soft/mattermost>
      Require all granted
      ProxyPass http://127.0.0.1:8083/
      ProxyPassReverse http://127.0.0.1:8083/
    </Location>
[...]
</VirtualHost>
</IfModule>

该网站是可访问的,但页面上什么也没有出现,因为我收到了这样的错误消息(其中一个例子是相同形式的):
Failed to load resource: the server responded with a status of 404 (Not Found) https://www.my.website.fr/static/main.9e27a2872d73987ea8ec.css

而不是尝试在以下位置访问文件:

https://www.my.website.fr/mattermost/static/main.9e27a2872d73987ea8ec.css(存在,我测试过)

(我用“my.website.fr”替换了我的网站域)

/mattermostapache代理没有使用前缀正确重定向有什么明显的原因吗?我错过了什么吗?

Mattermost 文档中的专用页面并没有帮助我解决这个问题(https://docs.mattermost.com/install/config-apache2.html

标签: apachereverse-proxymattermost

解决方案


来自 apache 文档:https ://httpd.apache.org/docs/2.4/mod/core.html#location

该指令通过 URL 限制所附指令的范围。

这意味着您需要更改:

<Location /home/www/www-soft/mattermost>
  Require all granted
  ProxyPass http://127.0.0.1:8083/
  ProxyPassReverse http://127.0.0.1:8083/
</Location>

<Location /mattermost>
  Require all granted
  ProxyPass http://127.0.0.1:8083/
  ProxyPassReverse http://127.0.0.1:8083/
</Location>

因为您的文档根目录设置为

DocumentRoot /home/www/www-website

您还使用 proxypass 处理对同一路径的请求

ProxyPass /mattermost http://localhost:8083
ProxyPassReverse /mattermost http://localhost:8083

您需要选择要实施的解决方案:两者可能无法很好地协同工作。

最后,你也在使用

ProxyPreserveHost On

我不确定它是否需要/按您的想法工作:请参阅https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypreservehost以了解您的环境是否真的需要它。


推荐阅读