Answer the question
In order to leave comments, you need to log in
Why does the websocket connection break on the VPS if there is no data exchange for ~ 1 minute?
nginx config:
proxy_read_timeout 950s;
server {
listen 80;
server_name 62.109.21.96;
root /home/user/ws-chat;
index index.php;
# add_header Access-Control-Allow-Origin *;
location / {
# add_header Access-Control-Allow-Origin *;
try_files $uri $uri/ /index.php?$query_string;
}
location /ws/ {
proxy_pass http://localhost:9502;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location ~* \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Answer the question
In order to leave comments, you need to log in
Libraries like socket.io get around this problem by sending something like a ping (implemented on both sides) every N seconds (for example, half a minute) to check if the connection is alive at the same time (otherwise some providers or buggy routers can also close TCP connections quietly if nothing has been transmitted through them for a long time).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question