如何在生产中启动 laravel-echo 服务器? [英] How to launch laravel-echo server on production?

查看:60
本文介绍了如何在生产中启动 laravel-echo 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的产品.堆栈:

  1. Vue.js CLI - https://example.com
  2. Laravel API - https://example.com/api

我已经使用 laravel-echo 服务器 创建了一个实时聊天 &socket.io 在我的本地主机上.
但是,我想在我的生产服务器上运行它.为此,我使用 nginx.

I've already created a real-time chat using laravel-echo server & socket.io on my localhost.
However, I want to run it on my production server. For that purpose I use nginx.

问题是,当我运行 laravel-echo-server start 时,它成功启动,但当我从网络浏览器访问我的网站时没有响应.(加入没有用)

The problem is that when I run laravel-echo-server start it launches successfully but gives no response when I access my site from web browser. (No use joined)

我已经重建了 vue 应用程序,清除了 Laravel 缓存并重新启动了 nginx 服务.

I've already rebuilt vue app, cleared laravel cache and restarted nginx service.

/etc/nginx/sites-enabled/default 我有:

server {
    server_name example.com www.example.com;

    root /var/www/html/Example/api/public/;    
    index index.html index.php;

    location / {
        root /var/www/html/Example/web/dist/;
        try_files $uri $uri/ /index.html;
    }

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

    location /api {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    }
}

我的 main.js 文件,我在其中连接到网络套接字:

My main.js file where I connect to web sockets:

import Echo from "laravel-echo"
window.io = require('socket.io-client')

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'https://example.com/socket.io',
    auth: {
        headers: {
            'Authorization': `Bearer ${localStorage.getItem('token')}`
        }
    }
});

我的laravel-echo.server.json:

{
    "authHost": "https://example.com/api",
    "authEndpoint": "/broadcasting/auth",
    "clients": [
        {
            appId: "xxxxx",
            key: "xxxxx"
        }
    ],
    "database": "redis",
    "databaseConfig": {
        "redis": {},
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": false,
    "host": null,
    "port": "6001",
    "protocol": "http",
    "socketio": {},
    "secureOptions": 67108864,
    "sslCertPath": "",
    "sslKeyPath": "",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "subscribers": {
        "http": true,
        "redis": true
    },
    "apiOriginAllow": {
        "allowCors": true,
        "allowOrigin": "*",
        "allowMethods": "GET, POST",
        "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
    }
}

推荐答案

尝试将此 host: 'https://example.com/socket.io' 更改为 host: 'https://example.com'

这篇关于如何在生产中启动 laravel-echo 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆