【问题标题】:Server Sent Event cant work on production environment服务器发送事件无法在生产环境中工作
【发布时间】:2016-04-15 18:01:21
【问题描述】:

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

【问题讨论】:

  • 这是一个 COR 问题。您的服务器需要使用正确的 Access-Control 标头进行响应。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-03-03
    • 2021-06-17
    • 2021-08-01
    • 2016-03-20
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    相关资源
    最近更新 更多