Kamran Malik
Kamran Malik

Reputation: 31

socket.io laravel echo not working in production in ubuntu

I'm using socket.io and laravel echo server with Redis and also SSL installed on the server but the socket.io file is not loading on the production ubuntu server everything works fine in my local window I'm not sure if I need any other configurations for production I also allow UFW 6001 port.

this is my laravel-echo-server.json file.

{
"authHost": "https://flowerful.initialengine.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "bb6e18dd7fd2e7aa",
        "key": "c52b04fae249d3cb303b317b281b1599"
    }
],
"rejectUnauthorized": false,
"database": "redis",
"databaseConfig": {
    "redis": {},
    "sqlite": {
        "databasePath": "/database/laravel-echo-server.sqlite"
    }
},
"devMode": true,
"host": null,
"port": "3001",
"protocol": "https",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "/etc/letsencrypt/live/flowerful.initialengine.com/fullchain.pem",
"sslKeyPath": "/etc/letsencrypt/live/flowerful.initialengine.com/privkey.pem",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
    "http": true,
    "redis": true
},
"apiOriginAllow": {
    "allowCors": true,
    "allowOrigin": "https://flowerful.initialengine.com",
    "allowMethods": "GET, POST",
    "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}

}

this is laravel echo server running on the production server.

I search on different portals and get some help and I apply some things following.

  1. Allow ufw port 6001
  2. run command laravel-echo-server init and create a config file
  3. give SSL the right paths

Some things in my mind may be happening. I installed virtual host may be apache2 not allow the domain to run on 6001 port

the URL is that is not working.

https://flowerful.initialengine.com:6001/socket.io/?EIO=3&transport=polling&t=NLFfgwB

enter image description here

Console window browser

Upvotes: 2

Views: 3025

Answers (3)

NIKUNJ KOTHIYA
NIKUNJ KOTHIYA

Reputation: 2165

If there is not a port problem on the server then you can do this my personal experience test.

What I would personally do is use an Nginx server as a reverse proxy. That way you could install an SSL certificate via Nginx and then proxy the traffic to the Laravel echo server.

The proxy rule would look as follows:

location /ws/{

    proxy_pass http://127.0.0.1:6001/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forwarded-For $remote_addr;
}

Then rather than using https://your_domain:6001 in your frontend, you would use https://your_domain/ws which would internally proxy the traffic to the echo server.

Let me know how it goes!

If you want to learn more about the production

Upvotes: 0

Oleh Diachenko
Oleh Diachenko

Reputation: 662

In my case, just port 6001 was closed. Check on server is project serve on your port:

curl -I localhost:6001

If you receive http headers, that mean is all ok and you need just open port.

For open port:

iptables -I INPUT -p tcp --dport 6001 --syn -j ACCEPT
service iptables save

Upvotes: 1

Nothehi
Nothehi

Reputation: 703

I think you should generate and set the right SSL file with .cert and '.key' extension for laravel-echo-server config like this:

"sslCertPath": "/{path_of_ssl}/flowerful.initialengine.com.cert.combined",
"sslKeyPath": "/{path_of_ssl}/flowerful.initialengine.com.key",

Upvotes: 1

Related Questions