Hi, I'm trying to connect websocket on real application server, but I stuck. Websocket and the web content is in the same place. I don't get it actually where is the problem. My browser saying ERR_CONNECTION_TIMED_OUT in console log. Screen shot in the below. What am i doing wrong ?

My Laravel Echo config:
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6001,
wssPort: 6001,
disableStats: true,
encrypted: true,
enabledTransports: ['ws', 'wss'],
});
My NGINX config file looks like:
map $http_upgrade $type {
default "web";
websocket "ws";
}
server {
# Listen HTTP
listen 80;
listen [::]:80;
# Server Name
server_name hidden-domain.com;
# Redirect to HTTPS
return 301 https://hidden-domain.com$request_uri;
}
server {
# Listen SSL
listen 443 ssl http2 deferred;
listen [::]:443 ssl http2 deferred;
# SSL Certificates
ssl_certificate /etc/nginx/ssl/app.pem;
ssl_certificate_key /etc/nginx/ssl/app.key;
# SSL Config
include h5bp/ssl/ssl_engine.conf;
include h5bp/ssl/policy_intermediate.conf;
# Include the basic h5bp config set
include h5bp/basic.conf;
# Root
root /var/www/app/public;
# Start Files
index index.html index.php;
# Server Name
server_name hidden-domain.com;
# Root directory
location / {
try_files /nonexistent @$type;
}
location @web {
try_files $uri $uri/ /index.php?$query_string;
}
location @ws {
proxy_pass http://127.0.0.1:6001;
proxy_set_header Host $host;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_redirect off;
# Allow the use of websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# PHP FPM
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
# Deny htaccess
location ~ /\.ht {
deny all;
}
}
broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'https',
],
],
websockets.php
'ssl' => [
/*
* Path to local certificate file on filesystem. It must be a PEM encoded file which
* contains your certificate and private key. It can optionally contain the
* certificate chain of issuers. The private key also may be contained
* in a separate file specified by local_pk.
*/
'local_cert' => '/etc/nginx/ssl/app.pem',
/*
* Path to local private key file on filesystem in case of separate files for
* certificate (local_cert) and private key.
*/
'local_pk' => '/etc/nginx/ssl/app.key',
/*
* Passphrase for your local_cert file.
*/
'passphrase' => null,
],
@ovunckesici did you solve this ERR_CONNECTION_TIMED_OUT console message?.
I'm getting this error too.
So I麓ve been trying to fix this error for 3 day and finally I came up with a solution. I hope it helps. First of all, go and watch this video.
If you did everything like that guy and you are still getting ERR_CONNECTION_TIMED_OUT, you probably have eighter problem with your SSL certificate - or (like me) closed port you are using for websockets.
I strongly recommend checking your SSL certificate paths (accesibilty) and your server firewall. Just to save you a few google searches - enter
sudo ufw status verbose in your linux server and you can see the list of opened ports. If your websockets port is missing in that list, type sudo ufw allow YOUR_WEBSOCKETS_PORT_NUMBER/tcp and voila, there it is. You can check if your websockets are running by entering http(s)://your.website.running.websockets:WEBSOCKETS_PORT. You should successfully connect with OK message.
This helped me solve my mysterious ERR_CONNECTION_TIMED_OUT problem and I hope it helps you too. Happy coding!
Most helpful comment
@ovunckesici did you solve this
ERR_CONNECTION_TIMED_OUTconsole message?.I'm getting this error too.