现在很多网站都使用https了,使用https加密目前看有利有弊。首先是安全,减少被劫持、篡改的机会。
给大家介绍的内容如下:
1.如何从阿里云申请个人免费证书
2.Nginx中配置HTTPS
1.申请证书
1:先登录阿里云官网,在产品服务里找到安全(云盾)-CA证书服务(数据安全)进入申请页面
购买好后,到我的证书里补全资料
绑定域名,提交个人信息,等完成后下载证书,按你的服务器环境来下载相应的证书,我这里以Nginx为例,安装配置方法里面也有说明
2.配置证书
在Nginx配置文件目录里新建一个cert目录,把下载的两个证书文件上传到cert目录里,214416805390762.pem,214416805390762.key
[root@XiaoFeng ~]# cd /usr/local/nginx/conf/
[root@XiaoFeng ~]# mkdir cert
修改Nginx的配置文件加入https配置
server {
listen 443;
server_name localhost;
ssl on;
root html;
index index.php index.html index.htm;
ssl_certificate cert/214416805390762.pem;
ssl_certificate_key cert/214416805390762.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 / {
root html;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
重启Nginx,这样就可以使用https://来访问你的网站了,如果你想把http://的访问跳转到https://上的话,可以在http的配置里加入跳转
加入红色里的内容