Skip to content

Nginx config missing websocket upgrade for Mattermost

After turning on Gitlab Mattermost, I tried to use it and got lots of HTTP 400 errors trying to open the websocket.

I found dozens of the following error in the Mattermost log file:

2015-08-24_19:15:51.46987 2015/08/24 19:15:51 http: multiple response.WriteHeader calls
2015-08-24_19:15:51.46990 [08/24/15 19:15:51] [EROR] websocket connect err: websocket: could not find connection header with token 'upgrade'
2015-08-24_19:15:51.46991 [08/24/15 19:15:51] [EROR] /api/v1/websocket:connect code=500 rid=MY_RID uid=MY_UID ip=MY_IP Failed to upgrade websocket connection [details: ]

When I added the following into the /var/opt/gitlab/nginx/conf/gitlab-mattermost-http.conf file, the websocket started to work:

  • At the top of the file:

     map $http_upgrade $connection_upgrade {
         default upgrade;
         '' close;
     }
  • Inside the location / block:

     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection $connection_upgrade;

These lines (or similar) should be added to the nginx config file template.