GithubHelp home page GithubHelp logo

Comments (9)

jonnywilliamson avatar jonnywilliamson commented on July 20, 2024 3

This is brilliant!

I use nginx and so I wanted to do the same for it. Lots of benefits to this, like no worries about having another port open in your firewall etc!

After some testing this is what you need to do to make this work with nginx.

Open your nginx conf file for the website you want to use the websockets on, it's normally found in /etc/nginx/sites-available/<yoursite.com>

server {
    listen 80;
    listen 443 ssl default_server;
    server_name example.com;
    root "/home/vagrant/example.com/public";

    index index.html index.htm index.php;

    charset utf-8;

### Add this section for websockets reverse proxy
### Assumes you want to run your laravel-echo-server on localhost with a port of 6001

    location /socket.io {
        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 Host $host;
        proxy_cache_bypass $http_upgrade;
    }

###END OF WEBSOCKETS SECTION

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
<snip>

Don't forget to restart nginx sudo service nginx restart.

Now you can set your laravel-echo-server.json to have the following:

<snip>
    "devMode": false,
    "host": "127.0.0.1",
    "port": "6001",
    "protocol": "http",
    "referrers": [],

And finally in your JS bootstrap.js file (or where ever you define Echo):

import Echo from "laravel-echo"
window.echo = new Echo({
    broadcaster: 'socket.io',
    host: { path: '/socket.io' }
});

That's the setup complete.

Just start the echo server (use the instructions) and then ensure that the page you load on your website has the JS loading ok. Your system is setup to receive broadcasts!

Thanks @alexmontoanelli - that's really cool!

from laravel-echo-server.

barryvdh avatar barryvdh commented on July 20, 2024

Does this use apaches ssl certificates, or do you still need to setup those in the config?

from laravel-echo-server.

alexmontoanelli avatar alexmontoanelli commented on July 20, 2024

You can set ssl on apache side in the usual way...will works ( I use here)

from laravel-echo-server.

antoniopaisfernandes avatar antoniopaisfernandes commented on July 20, 2024

Don't you have problems with the number of apache processes/threads that remain active/open because of the sockets?

from laravel-echo-server.

prince30 avatar prince30 commented on July 20, 2024

I am not able to setup on amazon ec2 using apache

from laravel-echo-server.

solancer avatar solancer commented on July 20, 2024

I get an errror

{
"code": 0,
"message": "Transport unknown"
}

screen shot 2017-12-08 at 1 37 17 am

from laravel-echo-server.

marcorivm avatar marcorivm commented on July 20, 2024

@solancer did you find a solutions? facing the same issue here

from laravel-echo-server.

createoop avatar createoop commented on July 20, 2024

With config :

<location /socket>
RewriteEngine On
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:3001/socket.io/%{QUERY_STRING} [P,L]
ProxyPass http://localhost:3001
ProxyPassReverse http://localhost:3001

i am getting error:

Error during WebSocket handshake: Unexpected response code: 400

from laravel-echo-server.

createoop avatar createoop commented on July 20, 2024

When i am using debug mode i see that thing:

engine bad request: unexpected transport without upgrade

from laravel-echo-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.