centos配置小程序https和wss协议
用nginx做代理,conf.d下ssl.conf配置成https,wss在nginx.conf里http某块中配置
例代码如下:
ssl.conf-->https
server { listen 443 ssl; #listen 443 ssl http2 default_server; #listen [::]:443 ssl; server_name www.zyin8.com; root /mnt/www/wenyin; ssl_certificate /etc/nginx/conf.d/cert/2_www.zyin8.com.crt; ssl_certificate_key /etc/nginx/conf.d/cert/3_www.zyin8.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_session_timeout 10m; #ssl_ciphers HIGH:!aNULL:!MD5; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / {
index index.html index.php index.htm;
}
location ~ \.php(.*)$ {
root /mnt/www/wenyin;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
nginx.conf-->wss
upstream wenyin{ server localhost:8282 weight=1; } server{ listen 443; server_name www.zyin8.com; root /mnt/www/wenyin; index index.php index.html index.htm; ssl on; ssl_certificate /etc/nginx/conf.d/cert/2_www.zyin8.com.crt; ssl_certificate_key /etc/nginx/conf.d/cert/3_www.zyin8.com.key; ssl_session_timeout 5m; ssl_session_cache shared:SSL:50m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on; access_log logs/wenyin_nginx.log main;
location /wss {
proxy_pass http://wenyin;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
小程序里使用wss://xxxx.com/wss