E
E
Evgeny Khripunov2018-08-10 17:47:13
Redis
Evgeny Khripunov, 2018-08-10 17:47:13

How to run laravel echo server ( +redis ) with external ip access (alias OpenServer)?

Windows has Open Server and Redis installed . Through Open Server in aliases:
1) Redirection from external ip to the final domain (vizitka/).
2) Redirection from local ip (192.168.0.102) to the final domain (vizitka/).
The site has a chat on websocket ( socket.io) .
When connecting to the site from the local ip , laravel echo authorization works fine. But if you connect from an external ip , then the site opens, but websocket connection requests are not executed:

http://внешнийIP:6001/socket.io/?EIO=3&transport=polling&t=MKaHXCl 0 ()

.env file
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

laravel-echo-server.json file
{
  "authHost": "http://vizitka/",
  "authEndpoint": "/broadcasting/auth",
  "clients": [
    {
      "appId": "APP_ID",
      "key": "e0702d5258f6bd18b91d52f7a37442f2"
    }
  ],
  "database": "redis",
  "databaseConfig": {
    "redis": {},
    "sqlite": {
      "databasePath": "/database/laravel-echo-server.sqlite"
    }
  },
  "devMode": true,
  "host": null,
  "port": "6001",
  "protocol": "http",
  "socketio": {},
  "sslCertPath": "",
  "sslKeyPath": "",
  "sslCertChainPath": "",
  "sslPassphrase": "",
  "apiOriginAllow": {
    "allowCors": false,
    "allowOrigin": "",
    "allowMethods": "",
    "allowHeaders": ""
  }
}

After authorization on the site, a connection to Echo occurs:
window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001',
    auth: {
        headers: {
            Authorization: 'Bearer ' + localStorage.getItem('token')
        },
    },
});

And then the user starts listening to his channel:
window.Echo.private('room.' + this.user_id)
    .listen('PrivateChat', ({data}) => {
        ...
    })

I tried to change authHost and host to http://externalIp/ in the laravel-echo-server.json file , but in this case, when executing the laravel-echo-server start command, it gives an error:
✔  Running at http://внешнийIp/ on port 6001
✔  Channels are ready.
✔  Listening for http events...
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND http://внешнийIp/
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)

Update:
In router wifi settings Forwarding > Virtual Servers:
1) Port: 80, ip address: 192.168.0.102 (was earlier)
2) Port: 6001, ip address 192.168.0.102 ( Added )
Connection to websocket via external ip now works.
Can you please tell me how this magic works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Ogureccc, 2020-02-06
@Ogureccc

Your client is learning from an external ip and not from a localhost, you opened the port on the router and everything should work, everything was correct

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question