Nginx的配置为WSS(Nginx config for WSS)

2019-07-29 05:31发布

我通过WSS连接到我的服务器有问题。 我跟着下面的文章设置的nginx使用WebSockets: http://www.letseehere.com/reverse-proxy-web-sockets

下面是我的nginx的配置,供应一玩! 应用:

#user  nobody;
worker_processes  1;  

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

tcp {

     upstream websockets {
      ## Play! WS location
       server 127.0.0.1:9000;
     }    

    server {
        listen 80; 
        listen 8000;
        server_name socket.domain.com;

        tcp_nodelay on; 
        proxy_pass websockets;
        proxy_send_timeout 300;
    }   

     # virtual hosting
     #include /usr/local/nginx/vhosts/*;
}

http {

  server {
        listen 443 ssl;
        server_name socket.artoo.in;

        ssl_certificate      /usr/local/nginx/key/socket.domain.com.crt;
        ssl_certificate_key  /usr/local/nginx/key/socket.domain.com.key;

        ssl_session_timeout  5m;

        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;

        location / {
            proxy_pass http://127.0.0.1:9000;
        }
  }
}

当服务器上访问http://socket.domain.com , https://socket.domain.com ,WS://socket.domain.com但不是WSS://socket.domain.com

Answer 1:

我能够把一个指南Q&将告诉您如何做到这一切与NGINX模块,更容易的格式;)

NGINX到反向代理的WebSockets和启用SSL(WSS://)?

您将需要重建NGINX并按照上面的问题的配置。



Answer 2:

我已经至少使用安全通道解决它在短期内(指这篇文章: http://www.darkcoding.net/software/proxy-socket-io-and-nginx-on-the-same-port-over -ssl / )。

安全通道可以转换成HTTPS HTTP和由令牌WSS到WS。 Nginx的服务于9000端口照常运行套接字应用程序:

/etc/stunnel/stunnel.conf

[https]
accept  = 443
connect = 80 
TIMEOUTclose = 0

/usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;  

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

tcp {

     upstream websockets {
      ## Play! WS location
       server 127.0.0.1:9000;
       check interval=3000 rise=2 fall=5 timeout=1000;
     }    

    server {
        listen 80; 
        listen 8000;
        server_name socket.artoo.in;

        tcp_nodelay on; 
        proxy_pass websockets;
        proxy_send_timeout 300;

    }   

     # virtual hosting
     #include /usr/local/nginx/vhosts/*;
}

#http {
#
#  server {
#        listen 443 ssl;
#        server_name socket.artoo.in;
#
#        ssl_certificate      /usr/local/nginx/key/socket.domain.com.crt;
#        ssl_certificate_key  /usr/local/nginx/key/socket.domain.com.key;
#
#        ssl_session_timeout  5m;
#
#        ssl_protocols  SSLv2 SSLv3 TLSv1;
#        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#        ssl_prefer_server_ciphers   on;
#
#        location / {
#            proxy_pass http://127.0.0.1:9000;
#        }
#  }
#}

现在,我需要担心的唯一的事情是如何提高对nginx的的WebSockets超时,连接似乎被打破每75秒(默认nginx的)。



文章来源: Nginx config for WSS