Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https/wss 配置,最新演示环境无法发送消息 #868

Closed
1 task
zhangchanglong opened this issue Jul 12, 2023 · 10 comments
Closed
1 task

https/wss 配置,最新演示环境无法发送消息 #868

zhangchanglong opened this issue Jul 12, 2023 · 10 comments
Assignees
Labels
bug 软件缺陷

Comments

@zhangchanglong
Copy link

现在行为

0712上午 在演示环境 https://demo.cskefu.com/ 测试,发现 无法发送消息

F12控制台提示:
socket.io.js:4163 WebSocket connection to 'wss://demo.cskefu.com:8036/socket.io/?userid=161e47d09233a9e4757b3beaa30a6ba8&session=359B486277B832F88E6DF1C7634DFD07&appid=104eac&osname=&browser=&skill=2c9e80867d65eb5c017d65f17ceb0019&nickname=Guest_%401ks1co&title=%E6%98%A5%E6%9D%BE%E5%AE%A2%E6%9C%8D%20%7C%20%E5%BC%80%E6%BA%90%E5%AE%A2%E6%9C%8D%E7%B3%BB%E7%BB%9F_%E6%99%BA%E8%83%BD%E5%AE%A2%E6%9C%8D_%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%AE%A2%E6%9C%8D&url=https%3A%2F%2Fdemo.cskefu.com%2Ftestclient.html&traceid=a6419758ade04c019e9f27ada49ef26f&EIO=3&transport=websocket'
failed: WebSocket is closed before the connection is established.

预期行为

能正常发送消息

操作系统

  • Windows

解决方案

代码版本

@zhangchanglong zhangchanglong added the bug 软件缺陷 label Jul 12, 2023
@hailiang-wang
Copy link
Member

WSS 链接默认是使用 443 端口,其设置识别是否有环境变量:

CS_IM_SERVER_SSL_PORT

docker compose 配置

# 春松客服配置 HTTPs / HTTPs for CSKeFu

@hailiang-wang
Copy link
Member

@lecjy

https 协议有类似的情况,解决办法是在后端渲染时,使用变量识别,设定 port,见

- var baseUrl = schemaFixed +'://' + hostname + ':' + portFixed

那么,websockets 也可以使用这个方案。 #846

@lecjy
Copy link
Collaborator

lecjy commented Jul 12, 2023

是在docker环境下才出现这个问题吗?

@hailiang-wang
Copy link
Member

docker 方式部署,但是该问题应该发生在使用反向代理配置 https/wss 的情况下。

docker 方式启动,docker compose 如下

  contact-center:
    image: ${CC_IMAGE:-cskefu/contact-center:develop}
    restart: always
    ports:
      - "${CC_WEB_PORT:-8035}:8035"
      - "${CC_SOCKET_PORT:-8036}:8036"
    volumes:
      - ./contact-center/data:/data
      - ./contact-center/logs:/logs
    environment:
      - "JAVA_OPTS=-Xmx${CC_JAVA_XMX:-12288m} -Xms${CC_JAVA_XMS:-2048m} -XX:PermSize=256m -XX:MaxPermSize=1024m -Djava.net.preferIPv4Stack=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true --illegal-access=warn"
      - SERVER_PORT=8035
      - SERVER_LOG_PATH=/logs
      - SERVER_LOG_LEVEL=${LOG_LEVEL:-WARN}
      - WEB_UPLOAD_PATH=/data
      - UK_IM_SERVER_PORT=8036
      - UK_IM_SERVER_HOST=localhost
      - UK_IM_SERVER_THREADS=10
      # 春松客服配置 HTTPs / HTTPs for CSKeFu
      # In detail
      #     1) https://chatopera.blog.csdn.net/article/details/105820829
      #     2) https://github.com/cskefu/cskefu/issues/414#issuecomment-1437767407
      # In short
      #     1) Setup Load Balancing / Reverse Proxy
      #     2) Modify CS_IM_SERVER_SSL_PORT
      #         2.1 comment out CS_IM_SERVER_SSL_PORT envronment variable to redirect HTTPs requests to 443 port
      #         2.2 Or just remove below line .
      - CS_IM_SERVER_SSL_PORT=443
      - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/cosinee?useUnicode=true&characterEncoding=UTF-8
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=${DB_PASSWD:-123456}

@hailiang-wang
Copy link
Member

该问题的现象是,环境变量 CS_IM_SERVER_SSL_PORT=443 没有发生作用。
即 sockets 连接是网页登陆后,html 模板中分析 sockets io 的连接地址,默认是 8036.

但是对于反向代理,https/wss 连接的 sockets 是通过 443 端口,所以,原来后端的逻辑是配置一个环境变量:CS_IM_SERVER_SSL_PORT,指定这个 sockets 端口,如果这个变量有值使用这个值,没有值使用默认(8036).

现在CS_IM_SERVER_SSL_PORT的值没有使用,而是使用了默认的 8036

@lecjy

lecjy pushed a commit that referenced this issue Jul 13, 2023
lecjy pushed a commit that referenced this issue Jul 13, 2023
@zhangchanglong
Copy link
Author

image

0714 15:39 测试 演示环境 还是不行,没有443端口

@lecjy
Copy link
Collaborator

lecjy commented Jul 15, 2023

443其实已经生效了,只不过默认不显示,主要的问题是后面的Error during webSocket handshake: Unexpected response code: 502,这个问题应该出在浏览器和反向代理之间

@hailiang-wang
Copy link
Member

hailiang-wang commented Jul 17, 2023

443其实已经生效了,只不过默认不显示,主要的问题是后面的Error during webSocket handshake: Unexpected response code: 502,这个问题应该出在浏览器和反向代理之间

首先,从浏览器访问websockets 至 443 已经生效,然后反向代理会访问 contact-center 容器的 8036 端(contact-center 使用的 websocket 端口,使用环境变量 CC_SOCKET_PORT=8036 配置)

见docker compose yml

screenshot_20230717094333

  1. 处是 springboot 中提供websocket server 的端口,2)处是端口映射出的地址,所以,3)和 2)应该一样。
    1)处是 docker 容器映射到宿主机器的地址,比如反向代理最终应访问这个地址。

现在在演示环境,已经通过访问宿主的机器的 443 端口,经过代理继续请求到 1) 处,那么 websockets 是不是运行在 3)处端口呢?即 8036 ?

@hailiang-wang
Copy link
Member

hailiang-wang commented Jul 17, 2023

@lecjy

经过查看,目前演示环境中,springboot 中 websockets server 启动服务的端口是 443,所以导致 BUG。

main]
 c.c.socketio.SocketIOServer - Session store / pubsub factory used: MemoryStoreFactory (local session store only) [main]
 c.c.socketio.SocketIOServer - SocketIO server started at port: 443 [nioEventLoopGroup-5-1]
 o.a.t.util.http.parser.Cookie - A cookie header was received [Hm_lvt_082d7d551961de56ada3f0d2aae042f3=1688005325,1689403234;] that contained an invalid cookie. That cookie will be ignored.

@hailiang-wang hailiang-wang changed the title 最新演示环境无法发送消息 https/wss 配置,最新演示环境无法发送消息 Jul 17, 2023
@lecjy
Copy link
Collaborator

lecjy commented Jul 17, 2023

那我理解错了

lecjy pushed a commit that referenced this issue Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 软件缺陷
Projects
None yet
Development

No branches or pull requests

3 participants