WebSocket握手期间出错:意外的响应代码:503

5

我正在尝试在Heroku上使用websocket rails与Angular进行通信。在开发环境中可以正常工作,但是在生产环境中出现了问题。以下是服务器代码发布事件和客户端监听事件的示例。

#Server
WebsocketRails[channel_name].trigger('new_message', @json)

//Client
var dispatcher = new WebSocketRails(window.location.host + "/websocket");
var channel = dispatcher.subscribe(channel_name);
channel.bind('new_message', function(data) {
  $scope.$apply(function(){
    cr.unread_messages += 1;
  });
});

我正在进行生产中的SSL设置。我已经尝试过设置

force_ssl = false

production.rb中尝试了,但无济于事。我收到的错误信息是:
WebSocket connection to 'wss://domain.com/websocket' failed: Error during WebSocket handshake: Unexpected response code: 503
1个回答

2

我遇到了同样的问题,我的应用程序在nginx后面。 检查一下我的Nginx配置,这是对我有效的。

location / {
  proxy_pass http://localhost:8080;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_set_header Host $host;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接