Reputation: 1267
I'm wondering what's the proper (or any for that matter) way of setting up Laravel Echo on an https production server. I've had it working on my local vagrant for a little bit now, and now that I've pushed the changes to production I'm unable to get the script to connect to the node server. Here is what I currently have.
var echo = require('laravel-echo-server');
var options = {
host: 'https://localhost',
port: '6001',
sslCertPath: '/etc/nginx/ssl/nginx.crt',
sslKeyPath: '/etc/nginx/ssl/nginx.key'
};
echo.run(options);
And then in javascript
import Echo from "laravel-echo"
window.echo = new Echo({
broadcaster: 'socket.io',
host: 'https://localhost:6001'
});
The above configuration is how I started out, but I've tried many other combinations, including trying to edit the nginx configuration to bypass https all together. If bypassing https is the method that's required, any advice on how to do this with Laravel Echo would be appreciated since the socket.io threads on this topic that I've been referencing don't seem to do the trick for me.
Upvotes: 7
Views: 19664
Reputation: 49
In addition to the user237329 response, the laravel echo setting in javascript should be:
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.host,
path: '/ws/socket.io',
});
Upvotes: 4
Reputation: 819
This is how I solved the problem
First. You have to configure your nginx vhost with ssl (no websocket connected yet). I use Let's encrypt ( https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
Second. You could create a path on your vhost to proxy to your websocket. This way nginx handles ssl protocol and also you do not use another port
location /ws/{
proxy_pass http://127.0.0.1:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
}
After that your script will have to connect to `https://localhost/ws/
Note: I use port 3000 for my laravel-echo-server
intance and not 6001 as stated in the original question
Upvotes: 9
Reputation: 1
Maybe someone will come here with the same problems as me. First, remember to add the untrusted certificate to browser exceptions, because for laravel echo port we have to do it separately. Otherwise you will get only connection refused in console. Secondly, the current version laravel echo does not accept the protocol in the host option, but in a separate option named 'protocol'.
Upvotes: 0
Reputation: 1267
I found the solution to this issue. When using Forge and Let's Encrypt, Forge will create folders with a unique ID at the start of the month that will contain your SSL keys. At first when I tried to use these keys, laravel-echo-server said it couldn't find the keys. In the code within my question above, I'm referencing two other keys that were on my server that I figured were a sym link to this months correct keys, but that turned out not to be the case. I did need to refer to the files within the unique ID folders. In order to get it to work, I simply had to run "sudo node socket.js".
Upvotes: 0