代理wss通过nginx(连接重置由对等)

我有浏览器和服务器上的IP地址abcd现在我有2个可能的URL到服务器:

  1. 通过浏览器通过Nginx

    browser -> https://abcd/ -> server 
  2. 通过从WSS的WSS

     browser -> wss://abcd:10062 -> server 

所以,443(nginx)上的服务器listnes和10062上的一些其他应用程序。我想要更改第二个连接到同一个端口(443):

 browser -> wss://abcd/someurl -> server 

那么是否有可能在nginx中代理abcd:10062,如下所示:

 server { listen 80; listen 443 ssl; ssl_certificate /path/to/crt/for/https; ssl_certificate_key /path/to/key/for/https; server_name abcd; location /someurl { -->> What to write here to create redirect for wss://abcd:10062 ? << -- } # the other locations here ('/', etc) # ... # ... } 

我接下来尝试:

 map $http_upgrade $connection_upgrade { default upgrade; '' close; } location /someurl { proxy_pass http://127.0.0.1:10062; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } 

但是当转到https:// abcd / someurl进行testing时,它会显示

 2015/12/14 16:12:51 [error] 371#0: *113 connect() failed (111: Connection refused) while connecting to upstream, client: my_ip, server: abcd, request: "GET /someurl HTTP/1.1", upstream: "http://127.0.0.1:10062/someurl", host: "abcd" 

但是!:Netstat显示这个:

 sudo netstat -tnlp | grep :10062 tcp 0 0 abcd:10062 0.0.0.0:* LISTEN 5702/webrtc2sip 

所以好像我需要指定abcd而不是127.0.0.1,所以我试了一下

 location /someurl { proxy_pass http://abcd:10062; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } 

结果:

 2015/12/14 16:54:11 [error] 13189#0: *123 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: my_ip, server: abcd, request: "GET /someurl HTTP/1.1", upstream: "http://abcd:10062/someurl", host: "abcd" 

好。 传递给代理人时,我打断了他的话:

 location = /someurl { return 302 /someurl/; } location /someurl/ { proxy_pass http://abcd:10062/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } 

现在,当我转到https:// abcd / someurl或https:// abcd / someurl /时 ,它会显示:

 2015/12/14 17:14:45 [error] 15836#0: *70 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: my_ip, server: abcd, request: "GET /someurl/ HTTP/1.1", upstream: "http://abcd:10062/", host: "abcd" 

为什么显示上游:“ http:// abcd:10062 / ”? 不应该显示“wss:// abcd:10062 /”吗?

回答你的问题:

“为什么显示上游:” http:// abcd:10062 / “?不应该显示”wss:// abcd:10062 /“?

Nginx以这种方式显示URI,因为这是在configuration中提供的:

 proxy_pass http://abcd:10062; 

我不认为细节是你的问题的一个指标,因为你似乎已经遵循了使用Nginx作为WebSocket代理的推荐语法 。