nginx-proxy icon indicating copy to clipboard operation
nginx-proxy copied to clipboard

Mattermost websocket+ CORS issue

Open hojoon-lee opened this issue 4 years ago • 1 comments

I'm getting connection timed out on mattermost behind the nginx proxy.

-e 'VIRTUAL_HOST1=wss://{MY_SERVER}/api/v4/websocket -> :8000 ;

I'm using the above argument.

My guess is that this is something that has to do with missing CORS headers . So I added the following

proxy_set_header Access-Control-Allow-Origin http://api.localhost;          
proxy_set_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE,PATCH

proxy_set_header Access-Control-Allow-Headers 
Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range;   

But these headers are not being added to the header.

Any pointer regarding the issue?

hojoon-lee avatar Dec 17 '20 17:12 hojoon-lee

The location part needs to be repeated so that it gets mapped correctly. otherwise it's forwarded to / instead of /api/v4/websocket.

There's another issue with mattermost websocket, It doesn't read the X-Forwarded-Host and uses the Host header instead. So it also needs to be modified. Following is my working configuration to fix the issue

    environment:
      - VIRTUAL_HOST_1=https://{MY_SERVER};client_max_body_size 50M;
      - VIRTUAL_HOST_2=wss://{MY_SERVER}"/api/v4/users/websocket->/api/v4/users/websocket;client_max_body_size 200M;proxy_set_header Host {MY_SERVER};
      - VIRTUAL_HOST_3=wss://{MY_SERVER}/api/v4/websocket->/api/v4/websocket;client_max_body_size 200M;proxy_set_header Host  {MY_SERVER};

mesudip avatar Dec 28 '20 05:12 mesudip