我在前端有一个Nuxt应用程序,在API上有Laravel。我已经通过Nginx代理在本地计算机上成功运行了Laravel回显服务器。当我将其部署到产品上时,我无法使其正常工作。除了端点,我在本地具有相同的配置。我的ws连接上总是显示状态3。
我不知道要寻找什么或如何调试套接字连接
nginx配置:
location /socket.io/echo/ {
proxy_pass http://127.0.0.1:6001;
proxy_set_header Host $host;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_redirect off;
# Allow the use of websockets
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;
}
答案 0 :(得分:0)
您可能需要配置laravel echo才能使用SSL。尝试像这样配置它:
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6001,
wssPort: 6001,
encrypted: true,
disableStats: true,
enabledTransports: ['ws', 'wss']
});
如果它不起作用,请确认您在后端使用了哪个软件包?是laravel-websockets吗?可能还需要为SSL配置它。
答案 1 :(得分:0)
这是一个愚蠢的错误。我正在使用的服务器托管了许多域。 API使用的域名不同于nuxt应用程序。更新了配置,使其指向API域名,现在可以正常使用了。谢谢!