随着大家对网站安全的重视,还有微信小程序开发的原因,大家都越来越重视网站SSL了。小编今天就给大家分享一下配置SSL的流程,并把非https跳转到https域名上。
1. 申请SSL证书,本文用的是阿里云的免费SSL证书,申请地址:https://common-buy.aliyun.com/?spm=5176.7968328.1266638..73dc1232tTWHHp&commodityCode=cas#/buy
2. 申请通过后,下载Nginx版本的证书文件,并上传到服务器。
3. 新增加配置.conf文件
server {
listen 443;
server_name www.boncent.com;
ssl on;
root /www/web/boncent/public_html;
ssl_certificate /www/nginx/cert/1451280_www.boncent.com.pem;
ssl_certificate_key /www/nginx/cert/1451280_www.boncent.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location / {
root /www/web/boncent/public_html;
index index.php index.html;
}
}
4. 重启Nginx,这步可以安排到第6步操作。
5. 编辑非https的配置文件,增加:
if ($host = "www.boncent.com") {
rewrite ^/(.*)$ https://www.boncent.com/$1 permanent;
}
让非https域名强制跳转到https域名上。
6. 重启Nginx。