nginx 代理 wss https for 微信小程序

安装nginx

apt-get install nginx

安装 PHP

 apt-get install php7.0

apt-get install php7.0-fpm

apt-get install php7.0-gd

apt-get install php7.0-mysql

apt-get install php7.0-mbstring

apt-get install php7.0-curl

安装mysql 

apt-get install mysql-server-5.7

主要修改nginx 的default 文件

map $http_upgrade $connection_upgrade {

    default upgrade;
    '' close;
}
upstream websocket {
    server www.yourname.cn:8282;  //websocket 监听的8282端口    (改成 127.0.0.1:8282)
}
server {
listen       443;
server_name  www.yourname.cn;
ssl on;
ssl_certificate /usr/local/apache/conf/1_www.yourname.cn_bundle.crt; //证书路径
ssl_certificate_key /usr/local/apache/conf/2_www.yourname.cn.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;
root /var/www/html;
index index.php index.html index.htm;
location / {
         try_files $uri $uri/ =404;

}

location /wss{

       proxy_pass http://websocket/;   # 代理到上面的地址去
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
}
location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
location ~ /\.ht {
                deny all;
        }

}


https  https://xxx.cn;

websocket  wss://xxx.cn/wws;

实现了根据路由转发

你可能感兴趣的:(lamp部署)