emqx nginx 代理 ws 崩溃

环境信息

  • EMQX 版本:4.4.3
  • 操作系统及版本:centos 8
  • 其他

问题描述

2022-04-29T20:39:38.975970+08:00 [error] crasher: initial call: cowboy_clear:connection_process/4, pid: <0.15278.4>, registered_name: [], error: {function_clause,[{cow_http_hd,token_ci_list,[<<226,128,156,117,112,103,114,97,100,101,226,128,157>>,[]],[{file,"cow_http_hd.erl"},{line,3463}]},{cow_http_hd,parse_connection,1,[{file,"cow_http_hd.erl"},{line,1164}]},{cowboy_http,connection_hd_is_close,1,[{file,"cowboy_http.erl"},{line,1333}]},{cowboy_http,maybe_req_close,3,[{file,"cowboy_http.erl"},{line,1306}]},{cowboy_http,after_parse,1,[{file,"cowboy_http.erl"},{line,332}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}, ancestors: [<0.1785.0>,<0.1784.0>,ranch_sup,<0.1595.0>], message_queue_len: 0, messages: [], links: [<0.15279.4>,#Port<0.88378>,<0.1785.0>], dictionary: [], trap_exit: true, status: running, heap_size: 987, stack_size: 29, reductions: 2234; neighbours:
2022-04-29T20:39:38.976885+08:00 [error] Ranch listener 'mqtt:ws:8083' had connection process started with cowboy_clear:start_link/4 at <0.15278.4> exit with reason: {function_clause,[{cow_http_hd,token_ci_list,[<<226,128,156,117,112,103,114,97,100,101,226,128,157>>,[]],[{file,"cow_http_hd.erl"},{line,3463}]},{cow_http_hd,parse_connection,1,[{file,"cow_http_hd.erl"},{line,1164}]},{cowboy_http,connection_hd_is_close,1,[{file,"cowboy_http.erl"},{line,1333}]},{cowboy_http,maybe_req_close,3,[{file,"cowboy_http.erl"},{line,1306}]},{cowboy_http,after_parse,1,[{file,"cowboy_http.erl"},{line,332}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}

配置文件及日志

upstream empx_ws {
        server 172.19.70.37:8083 max_fails=2 fail_timeout=30s;
        server 172.19.70.38:8083 max_fails=2 fail_timeout=30s;
}

server
{
        listen 80;
        listen 443 ssl http2;
        server_name apiyj.aaa.com;
        index index.php index.html index.htm default.php default.htm default.html;
        root /apps01/localhost;

        ssl_certificate  cert_aaa/server.cer;
        ssl_certificate_key cert_aaa/server.key;



        location / {
                proxy_redirect off;
                proxy_pass http://empx_ws;
                proxy_set_header Host $host;
                proxy_set_header X-Real_IP $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection “upgrade”;
        }
        access_log  /apps01/logs/access.log;
        error_log  /apps01/logs/error.log;
}

你去掉设置 upgrade header 的两行看看,看起来是这个 header 导致的报错

是那个upgrade的双引号符号问题,现在emqx不报错了。

但是ssl 卸载还是有问题
表现出来的是

[2022-05-05 11:31:52] [INFO] Connect client ssl-ws, MQTT/WSS connection: wss://mqttyj.xxx.com:443/mqtt
[2022-05-05 11:31:52] [INFO] ssl-ws connect close, MQTT.js onClose trigger

点击连接后直接关闭, nginx 没有访问日志。

服务器配置的证书为泛解析证书 *.xxx.com 不知道是不是证书问题?


upstream empx_ws {
        server 172.19.70.37:8083 max_fails=2 fail_timeout=30s;
#       server 172.19.70.38:8083 max_fails=2 fail_timeout=30s;
}

server
{
        listen 80;
        listen 443 ssl http2;
        server_name apiyj.xxx.com mqttyj.xxx.com;
        index index.php index.html index.htm default.php default.htm default.html;
        root /apps01/localhost;

        ssl_certificate  cert_xxx/server.cer;
        ssl_certificate_key cert_xxx/server.key;


        location /account/ {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://172.19.70.33:12000/;
        }

        location /upload/ {
                alias   /www/accountServer/upload/;
        }

        location / {
                proxy_redirect off;
                proxy_pass http://empx_ws;

                proxy_set_header Host $host;
                proxy_set_header X-Real_IP $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

        access_log  /apps01/logs/access.log;
        error_log  /apps01/logs/error.log;

                                                                              

但是直接用浏览器的mqtt.js 却能连上