ratchetphp websocket - 意外的响应代码:404

时间:2017-12-04 16:35:12

标签: nginx websocket ratchet

无法弄清楚导致此404错误的原因。 这是我的代码(Symfony命令):

protected function execute(InputInterface $input, OutputInterface $output)
{
    $loop = LoopFactory::create();

    $this->newsletterConsumer->consume($loop);

    @$server = new App($this->host, $this->port, $this->host, $loop);
    $server->route('/newsletters/{id}', $this->newsletterComponent, ['*'], $this->domain);

    $output->writeln(sprintf('Web-socket server started at %s:%s', $this->host, $this->port));

    $loop->run();
}

这里是:host - 127.0.0.1,port - 8081,domain - srcrm.dev

JS代码:

var connection = new WebSocket('ws://ws.srcrm.dev/newsletters/12');
...

Nginx配置:

server {
  listen 80;
  server_name ws.srcrm.dev;
  access_log off;

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

Chrome开发者工具显示:

WebSocket connection to 'ws://ws.srcrm.dev/newsletters/12' failed: Error during WebSocket handshake: Unexpected response code: 404

有人可以帮助理解这里的错误吗?

0 个答案:

没有答案