You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 10中Laravel WebSockets WSS无法通过Nginx连接问题求助

WSS连接失败排查(Laravel 10 + Laravel WebSockets + Nginx自签名SSL)

我基于Laravel 10框架,使用Laravel WebSockets、Pusher与Laravel-Echo开发项目。已通过Nginx配置自签名SSL证书,应用可正常通过HTTPS访问,但WebSocket Secure(WSS)无法在本地Windows机器上建立连接。

Nginx配置

listen 80 ;     
server_name real.web.com; 

listen 443 ssl;
ssl on;
ssl_certificate C:\certificate\websock\real.web.pem;
ssl_certificate_key C:\certificate\websock\private-key.pem;

root E:\\real-web\\public;

location / 
{
    index index.html index.htm index.php;
    try_files $uri $uri/ /index.php?$query_string;
}           

location ~ \.php$ 
{
    try_files $uri /index.php = 404;
    fastcgi_pass  127.0.0.1:8001;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location  /ws 
{
    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;
}         

.env配置

PUSHER_APP_ID=Zigma.v.0.01
PUSHER_APP_KEY=Zigma@123
PUSHER_APP_SECRET=Zigma@!@#
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=http
PUSHER_APP_CLUSTER=mt1

bootstrap.js配置

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1',
    wsHost: window.location.hostname,
    wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80, 
    wssPort:  443, 
    forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https',
    enabledTransports: ['ws', 'wss'], 
}); 

内容的提问来源于stack exchange,提问作者vasanthan dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 07:55:14