Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx websocket proxy disconnects after 2 minutes

I'm trying to proxy location to websocket upstream with nginx 1.9.11. Here's the config excerpt:

upstream autocloud_dispatcher {
  server 127.0.0.1:4000 fail_timeout=0;
}

server {
  .....
  location /ws {
    proxy_pass http://autocloud_dispatcher;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_connect_timeout 7d;
    proxy_send_timeout 7d;
    proxy_read_timeout 7d;
  }
}

Besides that I send ping messages from the backed every 90 seconds. But connection is still getting disconnected every 2 minutes. Some other setting in nginx that defaults to 120s?

like image 971
Ivan Yurov Avatar asked Feb 11 '16 18:02

Ivan Yurov


1 Answers

Setting timeout in seconds helped me, my config

location ~ /wss/(.*) {
    proxy_pass http://127.0.0.1:$1;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;

    proxy_read_timeout  36000s;

    proxy_redirect off;
}
like image 89
jegorenkov Avatar answered Sep 21 '22 03:09

jegorenkov