我安装了centrifugo它的实时消息传递服务器。 创建一个配置。
{
"secret": "a4b36637-1e1f-4865-840e-bed40c6253f9",
"token_hmac_secret_key": "9adb9887-638a-4e39-badf-b276c64afbdc",
"admin_password": "e21f5db0-fcf5-453c-89b7-9a5b9a8ab413",
"admin_secret": "a4b36637-1e1f-4865-840e-bed40c6253f9",
"api_key": "4271d87c-e014-40b0-886c-7778db912206",
"prometheus": true,
"debug": false,
"anonymous": false,
"client_insecure": false,
"port": 8000,
"address": "127.0.0.1",
"namespaces": [
{
"name": "public",
"publish": true,
"watch": true,
"anonymous": true,
"presence": true,
"join_leave": true,
"recover": false,
"history_size": 10,
"history_lifetime": 30
}
]
}
为centrifugo添加了块到nginx配置
location /centrifugo/ {
rewrite ^/centrifugo/(.*) /$1 break;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://127.0.0.1:8000;
}
location /centrifugo/connection {
rewrite ^/centrifugo(.*) $1 break;
proxy_next_upstream error;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
proxy_buffering off;
keepalive_timeout 65;
proxy_pass http://127.0.0.1:8000;
proxy_read_timeout 60s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
当我不运行centrifugo时,请转到链接site.com/centrifugo/site.com/centrifugo/admin 很明显,我的cloudflare出现502错误。
但是当我启动centrifugo时。 在控制台中给出404,site.com / centrifugo / admin,site.com / centrifugo / admin / auth /绘制404页面(直接在html中找不到)。 site.com/centrifugo/connection/sockjs/问题欢迎使用SockJS! site.com/centrifugo/connection/websocket发出了错误的请求。
但是我已经意识到,除了site.com/centrifugo/admin/auth /
之外,sockjs,websocket和api似乎都可以正常工作为什么网络界面可能无法正常工作?
要启动离心机,请使用以下命令:centrifugo -c config.json --admin
控制台输出:在127.0.0.1:8000上服务websocket,SockJS,API,admin,prometheus,debug,运行状况端点
我知道一切都会开始,但是由于某些原因,Web界面无法正常工作。
此外,当我尝试注册privateChannel时,它会发送请求到site.com/centrifuge/subscribe,以及我在js文件中发现的路径site.com/centrifuge/refresh。 Nginx不处理此类路径,因此会有404,应如何处理?
我遇到此错误
wrong status code in AJAX response 404
{message: "authorization request failed", code: 0, channel: "$private", isResubscribe: false}
let privateSub = centrifuge.subscribe('$private', function (message) {
console.log(message);
});
privateSub.on('error', (c) => console.log(c));
如何解决这样的问题?
何时使用generateConnectionToken,何时使用generatePrivateChannelToken?
谢谢大家。
我正在使用cloudflare和nginx。服务器通过https工作。