服务器发送事件无法在生产环境中工作

Server Sent Event cant work on production environment

我用 nodejs 做了一个简单的服务器发送事件。它 运行 在本地主机上完美无缺。当我将它上传到我的 VPS 时。订阅 link 的请求是 pending。我无法从后端收到任何消息。 Chrome 和 Safari 上的问题相同,没有控制台错误。在 Chrome 中,此请求类似于图像:

我发现了这个问题。这是一个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;
}