Dec 12, 2023
0
Level 10
Need Help with Socket.IO & Nginx Configuration on Laravel Forge
Hello everyone,
I'm currently facing an issue with configuring Socket.IO in a Laravel Forge environment using Nginx as a reverse proxy. While the static files (CSS, JS) are loading correctly, I'm unable to load the Socket.IO client script. I am consistently getting a 404 error when trying to access https://mydomain.com/socket.io/socket.io.js
Static files are served correctly from the public directory. However, the client-side Socket.IO script (socket.io/socket.io.js) returns a 404 error. that is my nginx config
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/yourdomain.com/before/*;
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name yourdomain.com;
server_tokens off;
root /path/to/your/public/directory;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /path/to/your/ssl_certificate.crt;
ssl_certificate_key /path/to/your/ssl_certificate_key.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers [Your_SSL_Ciphers];
ssl_prefer_server_ciphers off;
ssl_dhparam /path/to/your/dhparam.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/yourdomain.com/server/*;
# Redirect all other requests to Node.js server
location /socket.io/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Serve static files directly
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri $uri/ =404;
access_log off;
expires max;
}
access_log off;
error_log /path/to/your/error_log.log error;
location ~ /\.(?!well-known).* {
Please or to participate in this conversation.