nginx反向代理HTTPS WSS

    本文地址:http://tongxinmao.com/Article/Detail/id/291

    listen       443;

    server_name  xxxx.com;


    ssl on;

    ssl_certificate /xx/xx/cert.crt;

    ssl_certificate_key /xx/xx/cert.key;


    ssl_session_timeout 5m;

    ssl_session_cache shared:SSL:50m;

    ssl_protocols TLSV1.1 TLSV1.2 SSLv2 SSLv3;

    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

    ssl_prefer_server_ciphers on;


    #wss协议转发 小程序里面要访问的链接

    # 访问:wss://xxxx.com/wss

    location /wss {

        proxy_pass http://websocket;#代理到上面的地址去

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection "Upgrade";

    }


    #charset koi8-r;

    access_log  /var/log/nginx/log/xxx.access.log  main;


    location / {

        root   /data/www/xxxx;

        index  index.php index.html index.htm;

        try_files $uri $uri/ /index.php?$args;

    }




    wss.conf


    #主要是配置原来的ws 和 http 接口
    upstream websocket {
        server 10.5.11.xxx:8283;# 远程websocket服务器地址
    }
    upstream web{
        server www.xxx.com;# 远程http接口
    }
    # 通过下面的反向代理到上面的接口去
    server {
        listen 443;#默认https和wss协议端口
        ssl on;
        ssl_certificate /usr/nginx/conf/server.crt;#你的上传到服务器的证书位置
        ssl_certificate_key /usr/nginx/conf/server.key;#你的上传到服务器的证书位置
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        underscores_in_headers on;#开启自定义头信息的下划线
        #wss协议转发 小程序里面要访问的链接
        location /wss {
            proxy_pass http://websocket;#代理到上面的地址去
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }
        #https协议转发 小程序里面要访问的链接
        location /{
        proxy_pass http://web;#代理到原有的http的地址去
        proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        add_header Access-Control-Allow-Origin *;#跨域访问设置
        }
    }




    上一篇:webtcp 升级为WSS协议
    下一篇:微信小程序MQTT支持