Mattermost は標準で 8065/TCP を Listen します。 Apache を Reverse Proxy として動作させ、その配下で Mattermost を動作させる場合の Apache 設定例をメモしておきます。
前提条件
以下の条件で環境構築するものとします。
- Ubuntu16.04
- Mattermost 4.3.0
- Mattermost は Apache の VirtualHost として公開する
- Mattermost には HTTPS 接続を許可する
必要モジュールの有効化
WebSocket を Proxy させるので、必要モジュールを有効化しておきます。
a2enmod proxy_wstunnel
VirtualHost 用 設定ファイルの用意
Mattermost を Apache の VirtualHost として公開する為の設定ファイルを用意しておきます。 以下の内容で /etc/apache2/sites-available/mattermost.example.com.conf
というファイルを新規作成します。 ServerName
や証明書/秘密鍵等は適宜、置換します。
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mattermost.example.com
ServerAdmin hostmaster@example.com
ErrorLog /var/log/apache2/mattermost.error.log
CustomLog /var/log/apache2/mattermost.access.log combined
LogLevel warn
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api/v4/users/websocket [NC,OR]
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://127.0.0.1:8065%{REQUEST_URI} [P,QSA,L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://127.0.0.1:8065%{REQUEST_URI} [P,QSA,L]
<Location /api/v4/users/websocket>
Require all granted
ProxyPass ws://127.0.0.1:8065/api/v4/users/websocket
ProxyPassReverse ws://127.0.0.1:8065/api/v4/users/websocket
ProxyPassReverseCookieDomain 127.0.0.1 mattermost.example.com
</Location>
<Location />
Require all granted
ProxyPass http://127.0.0.1:8065/
ProxyPassReverse http://127.0.0.1:8065/
ProxyPassReverseCookieDomain 127.0.0.1 mattermost.example.com
</Location>
SSLCertificateFile /etc/ssl/certs/mattermost.example.com.crt
SSLCertificateKeyFile /etc/ssl/private/mattermost.example.com.key
</VirtualHost>
</IfModule>
設定ファイルが用意出来たらサイトを有効化し、Apache を再起動します。
a2ensite mattermost.example.com
systemctl restart apache2.service
参考
- [Solved] Apache2 ReverseProxy with websocket <-> https
- Apache経由でMattermostを使いたいとき
- How to setup a simple Apache2 Proxy to Mattermost?
- Docs » Administrator’s Guide » Installing Mattermost on Ubuntu 16.04 LTS
- Docs » Configuring Apache2 as a proxy for Mattermost Server (Unofficial)
- Troubleshooting
- Websockets error doesn't come back in Firefox after dismissal #872
コメント