我自己也遇到了这个问题,但是我已经正确设置了代理标头,但它仍然无法正常工作。但显然 Cloudflare 正在引起问题。这是一篇关于这个主题的精彩文章:https://meteorhacks.com/cloudflare-meets-meteor
据我所知,有三种解决方案:
选项 1:使用支持套接字的 CloudFlare 企业版。
选项 2: 禁用 Meteor WebSockets,这会影响您的性能,因为它会回退到使用 sock.js 作为替代品。为此,只需像这样设置您的流星环境:
export DISABLE_WEBSOCKETS=1
选项 3: 在 Cloudflare 中,为 websocket (ddp.yourdomain.com) 创建一个 ddp 子域,然后在新子域上禁用 Cloudflare。之后像这样设置你的流星环境:
export DDP_DEFAULT_CONNECTION_URL=http://ddp.example.com
在此之后,我的 nginx 配置需要进行一些调整,因为这现在已成为跨域 (CORS) 设置。这是我的新 nginx 配置:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80 proxy_protocol;
listen [::]:80 proxy_protocol;
server_name mydomain.com ddp.mydomain.com;
## This allows the CORS setup to work
add_header Access-Control-Allow-Origin 'http://example.com';
## This hides the CORS setup from the Meteor server
## Without this the header is added twice, not sure why?
proxy_hide_header Access-Control-Allow-Origin;
## Idealy the two options above should be disabeled,
## Then use this one instead, but that caused issues in my setup.
# proxy_set_header Access-Control-Allow-Origin 'http://example.com';
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host; # pass the host header
proxy_set_header Upgrade $http_upgrade; # allow websockets
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Real-IP $remote_addr; # Preserve client IP
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
# Meteor browser cache settings (the root path should not be cached!)
if ($uri != '/') {
expires 30d;
}
}
}
最后记得重启nginx。