如何解决如何在生产中启动 laravel-echo 服务器?
我的产品。堆栈:
- Vue.js CLI - https://example.com
- Laravel API - https://example.com/api
我已经在我的本地主机上使用 laravel-echo 服务器 和 socket.io 创建了一个实时聊天。
但是,我想运行它在我的生产服务器上。为此,我使用 nginx。
问题是,当我运行 laravel-echo-server start
时,它成功启动,但当我从网络浏览器访问我的网站时没有响应。 (加入没有用)
我已经重建了 vue 应用程序,清除了 Laravel 缓存并重新启动了 nginx 服务。
在 /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
文件:
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'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。