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

生产环境Reverb配置异常:WebSocket连接受阻问题求助

Laravel Reverb生产环境Socket连接问题修复

问题现象

本地运行Reverb正常,但生产服务器上Supervisor已启动,开发者工具网络标签中所有ws链接均指向localhost:8080且状态为blocked;尝试使用8080端口时提示:

无法监听"tcp://127.0.0.1:8080":地址已被占用(EADDRINUSE)

环境变量(env)配置

REVERB_APP_ID=396160  
REVERB_APP_KEY=ujjxjmewenx3ruqys4bf  
REVERB_APP_SECRET=ebqtdneudtyu3vategoj  
REVERB_SERVER_HOST=127.0.0.1  
REVERB_SERVER_PORT=6001  
REVERB_HOST=\"\\<my site's url\\>\"  
REVERB_PORT=443  
REVERB_SCHEME=https  
BROADCAST_CONNECTION=reverb 

Nginx配置

server {  
  listen 80;  
  listen [::]:80;  
  listen 443 quic;  
  listen 443 ssl;  
  listen [::]:443 quic;  
  listen [::]:443 ssl;  
  http2 on;  
  http3 off;  
  {{ssl_certificate_key}}  
  {{ssl_certificate}}  
  server_name <my site's url>;  
  {{root}}  

  {{nginx_access_log}}  
  {{nginx_error_log}}  

  if ($scheme != "https") {  
    rewrite ^ https://$host$uri permanent;  
  }  

  location ~ /.well-known {  
    auth_basic off;  
    allow all;  
  }  

  {{settings}}  

  try_files $uri $uri/ /index.php?$args;  
  index index.php index.html;  

  location ~ \.php$ {  
    include fastcgi_params;  
    fastcgi_intercept_errors on;  
    fastcgi_index index.php;  
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
    try_files $uri =404;  
    fastcgi_read_timeout 3600;  
    fastcgi_send_timeout 3600;  
    fastcgi_param HTTPS $fastcgi_https;  
    fastcgi_pass 127.0.0.1:{{php_fpm_port}};  
    fastcgi_param PHP_VALUE "{{php_settings}}";  
  }  

  location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf)$ {  
    add_header Access-Control-Allow-Origin "*";  
    expires max;  
    access_log off;  
  }  

  if (-f $request_filename) {  
    break;  
  }  
    
  location /app/ {  
    proxy_http_version 1.1;  
    proxy_set_header Host $http_host;  
    proxy_set_header Scheme $scheme;  
    proxy_set_header SERVER_PORT $server_port;  
    proxy_set_header REMOTE_ADDR $remote_addr;  
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    proxy_set_header Upgrade $http_upgrade;  
    proxy_set_header Connection "Upgrade";  
    proxy_pass http://0.0.0.0:6001;  
  }  
  location /apps {  
    proxy_http_version 1.1;  
    proxy_set_header Host $http_host;  
    proxy_set_header Scheme $scheme;  
    proxy_set_header SERVER_PORT $server_port;  
    proxy_set_header REMOTE_ADDR $remote_addr;  
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    proxy_set_header Upgrade $http_upgrade;  
    proxy_set_header Connection "Upgrade";  
    proxy_pass http://0.0.0.0:6001;  
  }  
}  

问题排查与修复

1. 修正环境变量配置错误

REVERB_HOST的转义符和多余引号会导致前端SDK获取错误地址,直接替换为实际域名:

REVERB_HOST=<my site's url>

(注意去掉所有引号和反斜杠,替换为你的真实域名)
这个错误是前端ws请求指向localhost:8080的核心原因——配置失效时SDK会 fallback 到默认地址。

2. 补全Nginx代理路径

Reverb默认前端连接路径为/reverb,当前Nginx配置缺少该路径的代理规则,添加以下配置:

location /reverb {
    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://127.0.0.1:6001;
}

原有/app/和/apps规则可保留(若有自定义路径需求),但必须确保/reverb路径被正确代理。

3. 解决8080端口占用问题

先排查占用8080端口的进程:

# 方式1:用lsof查找
lsof -i :8080
# 方式2:用netstat查找
netstat -tulpn | grep 8080

根据结果杀掉占用进程,或直接使用当前配置的6001端口(无需改用8080)。

4. 重启服务验证

  • 重启Reverb服务(通过Supervisor):
supervisorctl restart reverb
  • 重启Nginx:
nginx -s reload
  • 清除浏览器缓存后重新访问页面,检查网络标签中ws请求是否指向wss://<你的域名>/reverb,状态是否正常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.01 19:07:27