Giter Club home page Giter Club logo

Comments (1)

MaximMonin avatar MaximMonin commented on September 27, 2024

Docker-compose Example:

version: '3.7'

services:
  loadbalance:
    image: nginx:1.13.1
    container_name: laravel-loadbalance
    depends_on:
      - laravel
      - socketio
    expose:
      - 80
      - 443
    volumes:
      - ./nginx:/etc/nginx/conf.d
    environment:
      VIRTUAL_HOST: your.site
      VIRTUAL_PORT: 80
      LETSENCRYPT_HOST: your.site
      LETSENCRYPT_EMAIL: [email protected]
    networks:
      proxy:
      default:

  laravel:
    image: laravel
    container_name: laravel
    restart: always
    depends_on:
      - mysql
      - redis
      - socketio
    entrypoint:
      - bash
      - -c
      - |
        set -e
        echo 'Starting queue workers and scheduler'
        /start.sh
        echo 'Starting apache'
        exec apache2-foreground
    networks:
      default:
        aliases:
          - laravel
    volumes:
     - ./app:/app
     - ./mail:/etc/ssmtp
    ports:
     - '2380:80'
    expose:
      - 80

  redis:
    image: redis:5.0.7
    container_name: laravel_redis
    restart: always
    networks:
      default:
        aliases:
          - redis
    volumes:
      - ./redis:/data

  socketio:
    image: mintopia/laravel-echo-server
    restart: always
    container_name: laravel_socketio
    depends_on:
      - redis
    networks:
      default:
        aliases:
          - socketio
    expose:
      - 6001
    ports:
      - "6001:6001"
    environment:
      - LARAVEL_ECHO_SERVER_AUTH_HOST=http://laravel
      - LARAVEL_ECHO_SERVER_DEBUG=true
      - ECHO_DEVMODE=true
      - ECHO_PROTOCOL=http
      - ECHO_REDIS_PORT=6379
      - ECHO_REDIS_HOSTNAME=redis
      - ECHO_ALLOW_CORS=true
      - ECHO_ALLOW_ORIGIN=http://your.site

networks:
  default:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
  proxy:
    external:
      name: nginx-proxy

Nging proxy configuation: for load-balancer - split socketio and laravel trafic

upstream cluster_frontend {
     least_conn;
     server laravel:80;
}
upstream cluster_socketio {
     least_conn;
     server socketio:6001;
}

server {
    listen          80;

    location /socket.io {
            proxy_pass http://cluster_socketio;
	    proxy_http_version 1.1;
            proxy_set_header Host $http_host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
	}

    location / {
            add_header Cache-Control "no-cache";
            gzip_vary on;
            gzip_proxied any;
            gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
            proxy_pass http://cluster_frontend;
            include /etc/nginx/conf.d/proxy_params;
    }
}

Add to resourse/js/bootstrap.js

window.io = require('socket.io-client');
import EchoLibrary from "laravel-echo"
if (window.location.protocol == 'https:') // Under Nginx proxy
{
window.Echo = new EchoLibrary({
    broadcaster: 'socket.io',
    host: window.location.hostname,
});
}
else {                                   // Direct connect
window.Echo = new EchoLibrary({
    broadcaster: 'socket.io',
    host: window.location.hostname + ':6001'
});
}

laravel enviroment:

BROADCAST_DRIVER=redis
QUEUE_CONNECTION=redis

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_PREFIX=

from laravel-echo-server.

Related Issues (1)

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.