# How to setup a simple Apache2 Proxy to Mattermost?

**URL:** <https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495>\
**Category:** Troubleshooting\
**Created:** [November 9, 2015, 10:17am UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495 "2015-11-09T10:17:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrGoobri](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MrGoobri](https://forum.mattermost.com/u/MrGoobri)\
**Post date:** [November 9, 2015, 10:17am UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495/1 "2015-11-09T10:17:49Z")

</div>

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](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>
```

---

<div class="post-metadata">

**Author:** ![coreyhulen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/coreyhulen/32/25_2.png) [@coreyhulen](https://forum.mattermost.com/u/coreyhulen)\
**Post date:** [November 9, 2015, 4:37pm UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495/2 "2015-11-09T16:37:18Z")

</div>

This tix has a copy of an apache config that works

[https://mattermost.atlassian.net/browse/PLT-635](https://mattermost.atlassian.net/browse/PLT-635)

---

<div class="post-metadata">

**Author:** ![MrGoobri](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MrGoobri](https://forum.mattermost.com/u/MrGoobri)\
**Post date:** [November 12, 2015, 10:56am UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495/3 "2015-11-12T10:56:07Z")

</div>

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>
```

---

<div class="post-metadata">

**Author:** ![coreyhulen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/coreyhulen/32/25_2.png) [@coreyhulen](https://forum.mattermost.com/u/coreyhulen)\
**Post date:** [November 13, 2015, 3:39pm UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495/4 "2015-11-13T15:39:59Z")

</div>

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

```auto
 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]

```

---

<div class="post-metadata">

**Author:** ![booksprint](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/booksprint/32/1636_2.png) [@booksprint](https://forum.mattermost.com/u/booksprint)\
**Post date:** [November 16, 2015, 9:41pm UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495/5 "2015-11-16T21:41:30Z")

</div>

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

> <https://github.com/mattermost/mattermost-server/issues/872>
>
> If a websocket error occurs at it cannot reach the Mattermost server an error bar is displayed. This works correctly in...

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

---

<div class="post-metadata">

**Author:** ![TomaszGielda](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/tomaszgielda/32/393_2.png) [@TomaszGielda](https://forum.mattermost.com/u/TomaszGielda)\
**Post date:** [January 22, 2016, 9:33am UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495/6 "2016-01-22T09:33:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Wouter](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/wouter/32/290_2.png) [@Wouter](https://forum.mattermost.com/u/Wouter)\
**Post date:** [February 17, 2016, 9:50am UTC](https://forum.mattermost.com/t/how-to-setup-a-simple-apache2-proxy-to-mattermost/495/7 "2016-02-17T09:50:58Z")

</div>

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