1. 首页>
  2. 技术文章>
  3. nginx配置wss

nginx配置wss

3/22/22 3:57:49 PM 浏览 1606 评论 0

wss 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;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    map $http_upgrade $connection_upgrade {  
        default upgrade;  
        '' close;  
    } 
    upstream websocket {
            server 127.0.0.1:8181;#wssws:127.0.0.1:8181
    }
    server {
        listen       443 ssl;
        server_name  socket.gokolab.com;
           ssl_certificate      c:/cert/1.pem;
        ssl_certificate_key  c:/cert/1.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_verify_client off;
        ssl_prefer_server_ciphers  on;
        location / {
            proxy_redirect off;
            proxy_pass http://websocket;##ip
             proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 600s; ###10分钟没交互自动断开
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}


网友讨论