【问题标题】:Websockets nginx reverse proxy + CloudflareWebsockets nginx 反向代理 + Cloudflare
【发布时间】:2016-03-12 13:24:09
【问题描述】:

我正在使用NGINX代理 node.js websockets server,而我的子域正在使用CloudFlare 服务。
但是当我连接到 websocket 服务器时,我有这个错误WebSocket connection to 'ws://xxxx.xxxx.tld/' failed: Error during WebSocket handshake: Unexpected response code: 200
PS:当我通过 IP 地址直接访问时我没有这个错误:没有 NGINX 反向代理的端口。

这是我的NGINX 配置文件

server {
    listen 80;
    server_name xxxx.xxxx.tld;

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:89;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

有关信息,我使用的是最新版本的NGINX
怎么了?谢谢

【问题讨论】:

  • 您使用的是哪个 CloudFlare 计划?
  • 我正在使用免费计划

标签: node.js nginx proxy


【解决方案1】:

编辑:正如 Nickoplier 所说,CloudFlare 现在也支持免费计划的 WebSockets。请注意,免费计划中的 WebSocket 支持仅适用于低容量网站(根据support article)。

这不起作用,因为目前 CloudFlare 仅支持其业务和企业客户的 WebSockets(处于测试阶段)。请参阅support article 了解更多信息。

解决此问题的方法之一是创建一个未启用 CloudFlare 的新子域。例如 ws.xxxx.xxxx.tld,然后将您的 websockets 客户端指向它。

【讨论】:

  • 那么,如果我这样做,我的 VPS ip 将不再受到保护?
  • 没错。不幸的是,没有办法让 WebSockets 与免费计划一起工作,至少目前是这样。
  • 这不再适用,因为 Cloudflare 支持文章已更改。
猜你喜欢
  • 2011-08-09
  • 2013-02-18
  • 2020-03-24
  • 2016-04-11
  • 1970-01-01
  • 1970-01-01
  • 2018-08-06
  • 2013-05-25
  • 2016-11-10
相关资源
最近更新 更多