本节思路
由于微信小程序的网络请求都必须走HTTPS协议,于是打算用nginx反向代理go的websocket服务,这样在go的服务端,不用处理https,提高了性能。

根据之前的文章:江西小程序-给swoole的websocket server加上ssl
我们已经得到了一个pem文件和一个key文件

配置nginx

vi /etc/nginx/conf.d/yourdomain.conf

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
upstream gowebsocket {
    server 127.0.0.1:8929;
}
server {
    listen       443;
    server_name  yourdomain;

    ssl on;
    ssl_certificate /usr/local/ca/xxxxxxxxxxxxx.pem;
    ssl_certificate_key /usr/local/ca/xxxxxxxxxxxxxx.key;

    #charset koi8-r;
    access_log  /var/log/nginx/log/yourdomain.access.log  main;

    location / {
        proxy_pass http://gowebsocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

重启nginx