Server Sent Event无法在生产环境中工作

时间:2016-04-15 18:01:21

标签: node.js nginx server-sent-events eventsource

我使用nodejs创建一个简单的服务器发送事件。它在localhost上运行完美。当我将它上传到我的VPS。订阅链接请求为pending。我无法从后端收到任何消息。 Chrome和Safari上的问题相同,没有控制台错误。在Chrome中,此请求类似于图片:enter image description here

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。这是一个nginx问题。添加一些配置到nginx

location / {
  proxy_pass        http://127.0.0.1:3000;
  proxy_buffering off;
  proxy_cache off;
  proxy_redirect    off;
  proxy_set_header Connection '';
  proxy_http_version 1.1;
  chunked_transfer_encoding off;
  proxy_set_header  Host $host;
  proxy_set_header  X-Real-IP  $remote_addr;
}
相关问题