简体   繁体   English

Websockets Nginx反向代理+ Cloudflare

[英]Websockets nginx reverse proxy + Cloudflare

I'm using NGINX to proxy a node.js websockets server with my subdomain wich is using CloudFlare service. 我正在使用NGINX 代理一个node.js websockets server ,我的子域名正在使用CloudFlare服务。
But when I'm connecting to the websocket server, I have this error WebSocket connection to 'ws://xxxx.xxxx.tld/' failed: Error during WebSocket handshake: Unexpected response code: 200 但是当我连接到websocket服务器时,我有这个错误WebSocket connection to 'ws://xxxx.xxxx.tld/' failed: Error during WebSocket handshake: Unexpected response code: 200
PS: I don't have this error when I'm accessing directly by IP adress:port whitout NGINX reverse proxy. PS:通过IP地址直接访问NGINX反向代理时,我没有此错误。

Here's my NGINX config file : 这是我的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";
    }
}

For information, I'm using the latest version of NGINX . 有关信息,我正在使用NGINX的最新版本。
What's wrong? 怎么了? Thanks 谢谢

Edit: As Nickoplier noted, CloudFlare now supports WebSockets for the free plan too. 编辑:正如Nickoplier所说,CloudFlare现在也支持免费计划的WebSockets。 Be advised that the WebSocket support on the free plan is meant only for low-volume websites (per the support article ). 请注意,免费计划中的WebSocket支持仅适用于低容量网站(根据支持文章 )。

This does not work because currently CloudFlare only supports WebSockets (in a beta stage) for their business and enterprise customers. 这不起作用,因为目前CloudFlare仅支持其业务和企业客户的WebSockets(处于测试阶段)。 See the support article for more information. 有关更多信息,请参阅支持文章

One of the ways to workaround this is to create a new subdomain that is not CloudFlare-enabled. 解决此问题的方法之一是创建一个不支持CloudFlare的新子域。 For example ws.xxxx.xxxx.tld, and point your websockets client against that. 例如ws.xxxx.xxxx.tld,并指向您的websockets客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM