How to setup a simple Apache2 Proxy to Mattermost?

Hi,

I am trying to setup an Apache2 proxy from a subdomain to a port for mattermost.

I have downloaded the mattermost gzip file and extracted all files to /var/www/mattermost. I go to /var/www/mattermost/bin to run the platform script.

Going to http://mattermost.example.com gives me an Error 500 - Internal Server Error and I don’t know why. My apache2 config file is below but I just can’t figure out what is going wrong. I don’t get any error messages in the terminal output. Can anyone help?

<VirtualHost *:80>
    ServerName mattermost.example.com
    ServerAlias mattermost.example.com

    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8065/
    ProxyPassReverse / http://localhost:8065/
</VirtualHost>

This tix has a copy of an apache config that works

https://mattermost.atlassian.net/browse/PLT-635

Thanks for your help @coreyhulen but that gives me an error in my log files:

AH01144: No protocol handler was valid for the URL /api/v1/websocket. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule 

and I get a blue bar error message a few seconds after loading up the instance:

“We cannot reach the Mattermost service. The service may be down or misconfigured. Please contact an administrator to make sure the WebSocket port is configured properly.”

I have enabled tried to enable the proxy module like this:

$ sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Module proxy_http already enabled

Here’s my updated Apache VirtualHost file:

<VirtualHost *:443>
    ServerName mattermost.example.com
    ServerAlias mattermost.example.com

    DocumentRoot /var/www/mattermost

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/server.pem
    SSLCertificateKeyFile /etc/apache2/ssl/server.key

    ProxyPreserveHost On

    RewriteEngine On

    RewriteCond %{REQUEST_URI}  ^/api/v1/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]
    RequestHeader set X-Forwarded-Proto "https"

    <Location /api/v1/websocket>
        Require all granted
        ProxyPassReverse ws://127.0.0.1:8065/api/vi/websocket
        ProxyPassReverseCookieDomain 127.0.0.1 mattermost.example.com
    </Location>

    <Location />
        Require all granted
        ProxyPassReverse http://127.0.0.1:8065/
        ProxyPassReverseCookieDomain 127.0.0.1 mattermost.example.com
    </Location>
</VirtualHost>

Sorry, I’m not too familiar with apache, but I based on the error message we cannot establish a websocket connection to the mattermost server. Usually this means the connection cannot be upgraded from http:// to ws:// or https:// to wss://. The websocket connects on the same port. It starts off as the http protocol then gets upgraded to ws protocol.

I’m guessing somethings wrong with the following lines

 RewriteCond %{REQUEST_URI}  ^/api/v1/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]

Hi I had the same problem. Please see this thread and copy the config at the bottom of the comments:

I copied this and tweaked for my domain and it worked perfectly.

Hi everyone.
I configured Mattermost and Apache2 proxy, according to your instructions (thanks!). Everything is working just fine, exept of one thing: When a user joins new channel, or is switching between channels, before she or he can write messages - channel is reloading (sometimes one time, sometinmes few times) with messages replaced by “Loading…”. It is quite annoying.

There was no such problem, when there was no proxying through Apache, just nginx with mattermost, so I think it is issue connected with Apache proxying. Maybe someone had similar problem and can help?

Please check the pull request https://github.com/mattermost/docs/pull/25/files and give feedback if this solved the issue