beyondcode / laravel-websockets

Websockets for Laravel. Done right.
https://beyondco.de/docs/laravel-websockets
MIT License
5.08k stars 628 forks source link

Web Socket Not Running in Production server but working perfectly in Local Environment #1151

Closed NafeesKhabir closed 1 year ago

NafeesKhabir commented 1 year ago

Stuck at Starting the WebSocket server on port 6001...

Configs are as follows

.env

PUSHER_APP_ID=live PUSHER_APP_KEY=live PUSHER_APP_SECRET=live PUSHER_APP_CLUSTER=mt1

LARAVEL_WEBSOCKETS_HOST="server.example.xyz" LARAVEL_WEBSOCKETS_PORT=6001 LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/letsencrypt/live/server.example.xyz/fullchain.pem" LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/letsencrypt/live/server.example.xyz/privkey.pem" LARAVEL_WEBSOCKETS_SSL_PASSPHRASE= null

nginx

map $http_upgrade $type { default "web"; websocket "ws"; }

server {

server_name server.example.xyz;
root /home/pr_lnx/example/server/public/;

index index.html index.htm index.php;

location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location / {
    try_files /nonexistent @$type;
}

location @web {
    try_files $uri $uri/ /index.php$is_args$args;
}

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;
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/server.example.xyz/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/server.example.xyz/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server { if ($host = server.example.xyz) { return 301 https://$host$request_uri; } # managed by Certbot

listen 80;
listen [::]:80;

server_name server.example.xyz;
return 404; # managed by Certbot

}

Laravel 9

pusher-php-server:7.0.2

tried using both port 6001 and 443 https://example.fscd.xyz/laravel-websockets Also checked database during starting websocket it is not writing any event in database but during websocket:clean command it is giving following error SQLSTATE[HY000] [1045] Access denied for user 'exd_user'@'localhost' (using password: YES) (SQL: delete from websockets_statistics_entries where created_at < 2023-06-18 16:19:48)

rakhaxor commented 1 year ago

Found any solution? I am facing the same problem.

NafeesKhabir commented 1 year ago

Found any solution? I am facing the same problem.

Yes created separate service and modified service file to solve this. Now Working great

mghako commented 1 year ago

@NafeesKhabir Can you show me example, please.