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

websocket不支持ssl连接吗? #42

Closed
a08381 opened this issue Aug 18, 2020 · 6 comments
Closed

websocket不支持ssl连接吗? #42

a08381 opened this issue Aug 18, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@a08381
Copy link

a08381 commented Aug 18, 2020

 19:22:01 [WARNING] [CQHTTPMirai] Websocket连接出错, 未知错误, 请检查配置, 如配置错误请修正后重启mirai Server error(https://botapi.dead-war.cn/ws: 502 Bad Gateway.io.ktor.client.features.ServerResponseException
 19:22:09 [WARNING] [CQHTTPMirai] Websocket连接出错, 未知错误, 请检查配置, 如配置错误请修正后重启mirai Server error(https://botapi.dead-war.cn/ws: 502 Bad Gateway.io.ktor.client.features.ServerResponseException
 19:22:17 [WARNING] [CQHTTPMirai] Websocket连接出错, 未知错误, 请检查配置, 如配置错误请修正后重启mirai Server error(https://botapi.dead-war.cn/ws: 502 Bad Gateway.io.ktor.client.features.ServerResponseException
 19:22:25 [WARNING] [CQHTTPMirai] Websocket连接出错, 未知错误, 请检查配置, 如配置错误请修正后重启mirai Server error(https://botapi.dead-war.cn/ws: 502 Bad Gateway.io.ktor.client.features.ServerResponseException
 19:22:33 [WARNING] [CQHTTPMirai] Websocket连接出错, 未知错误, 请检查配置, 如配置错误请修正后重启mirai Server error(https://botapi.dead-war.cn/ws: 502 Bad Gateway.io.ktor.client.features.ServerResponseException

目前的配置文件如下:

  ws_reverse:
    # 可选,是否启用反向客户端,默认不启用
    - enable: true
      # 上报消息格式,string 为字符串格式,array 为数组格式
      postMessageFormat: string
      # 反向Websocket主机
      reverseHost: botapi.dead-war.cn
      # 反向Websocket端口
      reversePort: 443
      # 访问口令, 默认为空, 即不设置Token
      accessToken: token
      # 反向Websocket路径
      reversePath: /ws
      # 反向 WebSocket 客户端断线重连间隔,单位毫秒
      reconnectInterval: 3000
@a08381 a08381 closed this as completed Aug 18, 2020
@a08381 a08381 changed the title websocket不支持ssl连接?是否可以在配置文件中增加一个tls_enabled? websocket不支持ssl连接吗? Aug 18, 2020
@a08381 a08381 reopened this Aug 20, 2020
@b11p
Copy link

b11p commented Aug 22, 2020

502 Bad Gateway的话,是不是你反代没配置好?

@a08381
Copy link
Author

a08381 commented Aug 23, 2020

502 Bad Gateway的话,是不是你反代没配置好?

反向代理的配置我感觉是没有问题的

配置如下

#PROXY-START/
location /
{
    expires 12h;
    if ($request_uri ~* "(php|jsp|cgi|asp|aspx)")
    {
         expires 0;
    }
    proxy_pass http://127.0.0.1:8002;
    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 REMOTE-HOST $remote_addr;
    
    #持久化连接相关配置
    proxy_connect_timeout 30s;
    proxy_read_timeout 86400s;
    proxy_send_timeout 30s;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    add_header X-Cache $upstream_cache_status;
	#Set Nginx Cache

    proxy_ignore_headers Set-Cookie Cache-Control expires;
    proxy_cache cache_one;
    proxy_cache_key $host$uri$is_args$args;
    proxy_cache_valid 200 304 301 302 1m;
}

#PROXY-END/

@Hugozys
Copy link

Hugozys commented Aug 25, 2020

你好,我遇到了相同的问题,以下是我的反代配置:

upstream backend{
    server localhost:8080;	      
}
server
{
    server_name subdomain.tld;
    charset UTF-8;
    access_log      /var/log/nginx/uWSGI_access.log;
    error_log       /var/log/nginx/uWSGI_error.log;
	      
    client_max_body_size 75M;
    location / { 
	proxy_pass http://backend;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_connect_timeout 30s; 
        proxy_read_timeout 600s; 
        proxy_send_timeout 30s; 
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }   
    location /static {
        expires 30d;
        autoindex on; 
        add_header Cache-Control private;
        alias /home/ubuntu/project/static;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/subdomain.tld/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/subdomain.tld/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server
{
    if ($host = subdomain.tld) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name subdomain.tld;
    listen 80;
    return 404; # managed by Certbot
}

将反向WebSocket 端口 更改成443 之后遇到了与 @a08381 相同的错误

@Hugozys
Copy link

Hugozys commented Aug 25, 2020

I have 0 knowledge of kotlin language. Did a quick search through out the source repository and found this function definition:
https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-core/common/src/io/ktor/client/features/websocket/builders.kt#L133

Seeing we are using the following API when establishing the websocket session:
https://github.com/yyuueexxiinngg/cqhttp-mirai/blob/master/src/main/kotlin/tech/mihoyo/mirai/web/websocket/WebsocketReverseClient.kt#L91

Wondering whether this could be the culprit?

@a08381
Copy link
Author

a08381 commented Aug 25, 2020

I have 0 knowledge of kotlin language. Did a quick search through out the source repository and found this function definition:

https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-core/common/src/io/ktor/client/features/websocket/builders.kt#L133

Seeing we are using the following API when establishing the websocket session:

https://github.com/yyuueexxiinngg/cqhttp-mirai/blob/master/src/main/kotlin/tech/mihoyo/mirai/web/websocket/WebsocketReverseClient.kt#L91

Wondering whether this could be the culprit?

这么看起来的话,差不多就是我之前提的给ws反向连接添加一个tls_enabled配置就可以了

@yyuueexxiinngg yyuueexxiinngg added the bug Something isn't working label Aug 25, 2020
@yyuueexxiinngg
Copy link
Owner

已在新版中添加支持 .如有BUG请reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants