Mathias
Mathias

Reputation: 2010

Nginx timeout for websocket

I'm connecting a client with websocket through Nginx (as a reverse proxy) to an asp.net core application. Between server and client there are heartbeat commands to keep websocket connection open.

My Problem is when a client disconnects by unplugging the network cable the connection remains open. I would like to set a timeout that when the client doesn't send anything for a certain time that the connection gets closed.

I tried multiple timeouts without any effect. (proxy_send_timeout, client_body_timeout, keepalive_timeout, send_timeout...) The only timeout I managed to set was proxy_read_timeout. What I didn't like was that this timeout was reset every time the server send anything (and not the client).

Which timeout do I have to set to disconnect the client if the client doesn't send anything for x seconds?

Upvotes: 0

Views: 1536

Answers (1)

Sean Huh
Sean Huh

Reputation: 3

Have you tried this configuration?

 location /ws {
                proxy_read_timeout 300s;
                proxy_connect_timeout 75s;
            proxy_pass https://your_channel_daphne;
                proxy_http_version 1.1;
                proxy_set_header    Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_redirect off;
                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-Host $server_name;
        }

I tried that and resolved.

Upvotes: 0

Related Questions