tg123 / websockify-nginx-module

Embed websockify into Nginx (convert any tcp connection into websocket)
MIT License
141 stars 60 forks source link

单独使用websockify和nginx内置websockify的不同效果(代理转发失败) #12

Closed lulersoft closed 6 years ago

lulersoft commented 6 years ago

单独使用websockify进行转发代理是成功的,使用nginx内置websockify模块,提示协议错误。

127.0.0.1:64738 是聊天服务器

单独使用的代码: websockify 64737 127.0.0.1:64738 --ssl-target -v --traffic --cert ./self.pem --key .self.pem

nginx配置: server { listen 443 ssl; server_name voice.example.com; ssl_certificate /etc/letsencrypt/live/voice.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/voice.example.com/privkey.pem;

    location /chat{
            proxy_pass http://127.0.0.1:64737;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
    }

}

map $http_upgrade $connection_upgrade { default upgrade; '' close; }

以上是独立使用websockify是运行成功的。

下面是根据本模块的用的配置:

server { listen 443 ssl; server_name voice.example.com; ssl_certificate /etc/letsencrypt/live/voice.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/voice.example.com/privkey.pem;

    location /chat {
            websockify_pass 127.0.0.1:64738;
    }

}

使用内置服务器提示错误:

2018-03-27 23:30:47.746 1 => <31:(-1)> New connection: 127.0.0.1:29758 2018-03-27 23:30:47.762 1 => <31:(-1)> Connection closed: Error during SSL handshake: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol [13] 这是啥原因呢?用内置模块就简单方便了很多,但是目前运行不起来。 nginx版本是 1.10.1,下面是编译配置: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-1.0.2h --with-pcre=../pcre-8.38 --with-pcre-jit --with-ld-opt='-ljemalloc' --add-module=../websockify-nginx-module/
tg123 commented 6 years ago

从错误来看你这个还没有走到 websockify_pass ssl 握手就失败了啊

建议先把 https 关了 验证下 websockify_pass

lulersoft commented 6 years ago

这是浏览器的头部信息:

Request URL:wss://我服务器的地址/chat Request Method:GET Status Code:101 Switching Protocols Connection:upgrade Date:Wed, 28 Mar 2018 11:04:12 GMT Sec-WebSocket-Accept:Pa27LTdRa4KkmixYLRExU9aNrtA= Sec-WebSocket-Protocol:binary Server:nginx Upgrade:websocket Accept-Encoding:gzip, deflate, br Accept-Language:zh-CN,zh;q=0.9 Cache-Control:no-cache Connection:Upgrade Host:我服务器的地址 Origin:https://我服务器的地址 Pragma:no-cache Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits Sec-WebSocket-Key:q/bl2zcPugUxvGSMA42y7w== Sec-WebSocket-Protocol:binary Sec-WebSocket-Version:13 Upgrade:websocket User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36

lulersoft commented 6 years ago

看起来是已经握手成功了,问题是其它的吧?

tg123 commented 6 years ago

127.0.0.1:64738 是 ssl 协议吗 websockify_pass 目前不支持 upstream 是 ssl 协议的情况

lulersoft commented 6 years ago

独立执行websockify: websockify 64737 127.0.0.1:64738 --ssl-target -v --traffic --cert ./self.pem --key .self.pem

执行提示: WebSocket server settings:

你做的模块和独立的websockify有任何关系吗?

lulersoft commented 6 years ago

啥时候更新一下你的模块:),不然另外开个websockify 不太方便。

tg123 commented 6 years ago

目前并没有计划支持 upstream 使用 ssl 协议