tryzealot/zealot

[求助]: cable 连接不上;跨域问题;注册点击无反应

Closed this issue · 13 comments

部署方式 | How to Deploy

使用一键部署脚本 | Using zealot-docker on-click install (Default)

部署版本 | Version

nightly (Default)

反代服务 | Reverse Proxy

nginx

HTTPS 证书类型 | HTTPS(SSL)

无 none

已阅读文档 | Read the document

  • 已阅读 | Yes

描述 | Description

我这台服务器是从另一台服务器上代理过来的,所有流量走 80 端口。
然后我把 docker 映射到服务器的 9527 端口,服务器的 nginx 把 80 端口的流量都转发到 9527,然后发现出来的网页一直有几个问题。

看控制台,首先是有个 /cable 一直连不上,显示 WebSocket connection to 'wss://xxx/cable' failed: There was a bad response from the server.

其次是点第三方登录显示跨域问题:Origin https://xxx is not allowed by Access-Control-Allow-Origin. Status code: 200

最后是注册按钮点击无反应,错误如下:

Error: Form responses must redirect to another location
requestSucceededWithResponse — application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js:14198
(匿名函数) — application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js:13969
asyncFunctionResume
(匿名函数) — application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js:13947
asyncFunctionResume
(匿名函数)
promiseReactionJobWithoutPromise
promiseReactionJob

不知道是不是之前没有过和我类似的情况。请大佬指点怎么解决?

问题日志 | Relevant log output

我的 nginx 配置如下:
    
server {
        listen       80;
        server_name  xxx;

#	location ~* ^(/assets|/favicon.ico) {
#		access_log      off;
#		expires         max;
#	}
# 上一段取消注释,可以解决跨域问题,但会导致 css/js 等资源文件取不到

	location / {
		try_files $uri @zealot;
	}

	location @zealot {
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header Proxy "";
		proxy_pass_header Server;

		proxy_pass http://0.0.0.0:9527;    # 根据实际情况修改地址和端口号
		proxy_buffering on;
		proxy_redirect off;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
	}

	location /cable {
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_pass http://0.0.0.0:9527;    # 根据实际情况修改地址和端口号
	}
    }

感谢你提交的问题或反馈,我会在有时间的时候回复在此期间你可以看看之前被解决的反馈说不定有你需要的答案。
Thanks for opening this issue, a maintainer will get back to you shortly!

如果是同一台机器使用 docker 部署的话,可以使用同一个 docker network 可以走容器内网络;
如果不是的话上面的 IP 应该是错误的吧 0.0.0.0 不应该可以正常被访问到,需要指定到具体的 IP 地址上。

不是同一台服务器。SSL 证书在服务器 A 上,我的项目部署在服务器 B 上。A 把我的域名转发到 B:80。因此我在 B 上部署了 docker 之后,用 nginx 把 80 的数据都转发到了 docker 的对外端口。这时候要怎么配置 B 上的 nginx 呢?

我是看 docker ps 里是这么写的:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8eec0d16c88 ghcr.io/tryzealot/zealot:nightly "/init" 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:9527->80/tcp

你看我的理解是否正确:

  • A 服务器是 Nginx 反代或 LB,假如 IP 是 172.1.1.1
  • B 服务器是 Docker 部署的 zealot 对外暴露的端口是 9527,对 A 服务器可访问的 IP 是 172.1.1.2

B 无论是使用 docker 还是 docker-compose 部署,正常使用 171.1.1.2:9527 是可以正常访问的。而 A 在 nginx 的配置应该是:

location @zealot {
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header Proxy "";
		proxy_pass_header Server;

-		proxy_pass http://0.0.0.0:9527;    
+		proxy_pass http://171.1.1.2:9527;
		proxy_buffering on;
		proxy_redirect off;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
	}

	location /cable {
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
-		proxy_pass http://0.0.0.0:9527;    
+		proxy_pass http://171.1.1.2:9527;
	}

nginx 只是负责加 SSL 证书其余的任务则是把规则转发到 B 的 zealot 服务上面。

多谢大佬回复~

我这边最主要的问题是 A 服务器属于统一管理,没有配置的权限,只做了一件事,就是把所有请求都转发到了 B:80。
所以我的 nginx 配置是放在 B 上的,我在 B 上把所有来自 80 的流量转发到 9527,也就是 docker 服务上。
然后就出现了上面说的问题。

我昨天也是过把 0.0.0.0 改成 127.0.0.1,还是一样的问题。

目前来看是登录(预定义管理员账号)、上传、下载等功能都没问题,就注册、(第三方登录 | assert 加载)会有问题。

估计是第一层反代的配置不正确造成的,等着这个成功跑完后在 zealot 的 .env 环境变量文件新增:

ZEALOT_DISABLE_CABLE_REQUEST_PROTECTION=true

关闭 cable 的请求保护看看是否有效果。

大佬,我试了下,现在报错是:

[Log] [ActionCable] – "ConnectionMonitor detected stale connection. reconnectAttempts = 3, time stale = 32.873 s, stale threshold = 6 s" – 1668144022477 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Log] [ActionCable] – "ConnectionMonitor reopening" – 1668144022477 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Log] [ActionCable] – "Reopening WebSocket, current state is closed" – 1668144022477 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Log] [ActionCable] – "Opening WebSocket, current state is closed, subprotocols: actioncable-v1-json,actioncable-unsupported" – 1668144022477 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Error] WebSocket connection to 'wss://xxx/cable' failed: There was a bad response from the server.
[Log] [ActionCable] – "WebSocket onerror event" – 1668144022514 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Log] [ActionCable] – "WebSocket onclose event" – 1668144022514 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Log] [ActionCable] – "ConnectionMonitor detected stale connection. reconnectAttempts = 4, time stale = 43.48 s, stale threshold = 6 s" – 1668144033084 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Log] [ActionCable] – "ConnectionMonitor reopening" – 1668144033084 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)
[Log] [ActionCable] – "Reopening WebSocket, current state is closed" – 1668144033084 (application-a6c0272bfdcd3fded69270e0048f85ece58e49fd.js, line 19752)

在循环。另外跨域问题还是有。

目前我本级配置是只保留了这一段:


        location / {
                try_files $uri @zealot;
        }

        location @zealot {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header Proxy "";
                proxy_pass_header Server;

                proxy_pass http://127.0.0.1:9527;    # 根据实际情况修改地址和端口号
                proxy_buffering on;
                proxy_redirect off;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
        }

        location /cable {
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_pass http://127.0.0.1:9527;    # 根据实际情况修改地址和端口号
        }

我实在复现不出来,最好是把 A 服务器的配置贴下

配置如下:

upstream xxx_servers {
      server B max_fails=3 fail_timeout=30s ;
    }

    server {
        listen       443  ssl;
        server_name  xxx;
        #ssl on;
        ssl_certificate /etc/nginx/ssl/xxx/server.cert;
        ssl_certificate_key /etc/nginx/ssl/xxx/server.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers     ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;

        location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://xxx_servers/;
        }
}

server {
    listen  80;
    server_name xxx;

    rewrite ^(.*)$  https://$host$1 permanent;

}

@icyleaf 大佬,用上面这个配置能复现吗?

上面配置没有设置 WebSocket 的转发可能有问题,参考从websocket服务的nginx配置说起的解释,需要加 proxy_set_header Connection "upgrade";

第三方登录无法点击确实可以复现,是另外一个问题引发的 eb53fdc 已修复

@icyleaf DLNB,两个问题都已经解决了,感谢~