JeecgBoot icon indicating copy to clipboard operation
JeecgBoot copied to clipboard

https websocketFilter不调用,前端提示连接websocket失败

Open LelandACM opened this issue 2 years ago • 2 comments

版本号:

3.4.0

前端版本:vue3版?还是 vue2版?

vue3

问题描述:

目前我是在服务器端开启https image

不启用https使用http websocket正常使用,使用https,前端websocket连接失败,调试发现是后台websocketFilter不进入(在使用http时会进入此函数)

截图&代码:

image image

友情提示(为了提高issue处理效率):

  • 未按格式要求发帖,会被直接删掉;
  • 描述过于简单或模糊,导致无法处理的,会被直接删掉;
  • 请自己初判问题描述是否清楚,是否方便我们调查处理;
  • 针对问题请说明是Online在线功能(需说明用的主题模板),还是生成的代码功能;

LelandACM avatar Sep 20 '22 00:09 LelandACM

报什么错,https证书什么的都配置正确了吗

zhangdaiscott avatar Sep 20 '22 01:09 zhangdaiscott

@zhangdaiscott 证书都OK,其他接口都可用,前端错误如上图,服务器端无任何错误消息,正常情况下会打印这条日志的,但是没有进来

        log.info("websocket连接 Token安全校验,Path = {},token:{}", request.getRequestURI(), token);

LelandACM avatar Sep 20 '22 01:09 LelandACM

https情况websocket需要额外加配置 image

zhangdaiscott avatar Sep 27 '22 13:09 zhangdaiscott

  1. 发现使用https部署时,一开始可以发送websocket信息,能够响应,过一会儿在发送同样的消息,就不响应了。(不无痕刷新,只有按F5才会强制刷新处理新消息)
  2. 一开始打开页面初始化,也没有看到浏览器console那里打印【WebSocket】连接成功 image image

sendMsg接口发送消息成功,websocket未无痕刷新,我查看服务器日志发现【Redis发布订阅模式】这句有打印 image

我的nginx配置文件如下

server {
        listen 443 ssl;
        server_name xxx;
        ssl_certificate D://nginx-1.20.2//cert//8459666_xxx.pem;
        ssl_certificate_key D://nginx-1.20.2//cert//8459666_xxx.key;
        ssl_session_timeout 60m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        #表示使用的加密套件的类型。
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
		ssl_verify_client off;
        # 要支持websocket
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        
        location / {
            # 用于配合 browserHistory使用
		    try_files $uri $uri/ /index.html;
            root   html;
			index  index.html index.htm;
        }

        location /jeecgboot/ {
            proxy_pass https://127.0.0.1:8443/jeecg-boot/;
            proxy_redirect off;
            #真实IP获取
            proxy_set_header  Host             $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            set $my_proxy_add_x_forwarded_for $proxy_add_x_forwarded_for;
            if ($proxy_add_x_forwarded_for ~* "127.0.0.1"){
            set $my_proxy_add_x_forwarded_for $remote_addr;
            }
			# 要支持websocket
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

         location /websocket/ {
            proxy_pass https://127.0.0.1:8443/jeecg-boot/websocket/;
            proxy_redirect off;
            #真实IP获取
            proxy_set_header  Host             $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            set $my_proxy_add_x_forwarded_for $proxy_add_x_forwarded_for;
			# 要支持websocket
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
        
        location /upload {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            add_header Access-Control-Allow-Methods *;
            add_header Access-Control-Allow-Origin $http_origin;
            proxy_pass https://127.0.0.1:8443/jeecg-boot/;
        }
		
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }

LelandACM avatar Nov 10 '22 02:11 LelandACM

补充刚刚发现的一个情况,我搜索服务器日志,一开始连接websocket的时候发现doFilter应该是没有进来,下面这句没有打印 image

并且在心跳检测不执行前,我的websocket都可用,只要自动调用了心跳检测后,发送的消息就不能无痕刷新了,请知晓 image 心跳响应后,websocket就断开连接了【服务器后台日志看到的情况】 image

@zhangdaiscott 请求帮助,我现在判断不出来,是前端有问题,还是nginx配置有问题o(╥﹏╥)o

LelandACM avatar Nov 10 '22 02:11 LelandACM