http 升级为 https 访问
1.获取免费的CA证书。
2.然后填写信息申请
3.下载对应证书
4.上传证书到你的服务器
cd usr/local/nginx/conf/vhost
mkdir cert
将.key和.pem后缀文件上传到cert文件夹,并重命名xxx.key,xxx.pem
5.配置nginx(最好把之前80端口的配置备份一份)
server
{
listen 443 ssl;
server_name xxxxxxxx;//你备案好的域名
index index.html index.htm index.php default.html default.htm default.php;
root xxxxxxx;#项目目录
ssl_certificate cert/cfun.pem;
ssl_certificate_key cert/cfun.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;
include rewrite/y.conf;
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/y.log;
}
server {
listen 80;
server_name xxxxxxxx;//你备案好的域名;
access_log /home/wwwlogs/y.log;
rewrite ^(.*)$ https://$host$1 permanent; #把http的域名请求转成https
}
}
Nginx 支持 rewrite 功能。若您在编译时没有去掉 pcre,您可在 HTTP 的 server 中增加
rewrite ^(.*) https://$host$1 permanent;
即可将默认80端口的请求重定向为 HTTPS。
6.重启nginx,访问域名:www.xxx.com .自动跳转https安全访问;如图
7.总结:第一次听别人说配安全证书,心生羡慕,有一种来自菜鸟的仰慕。当你接触了才发现,原来如此。。。哈哈。多动手,多思考。Believe in yourself, everything is the beginning of the best!
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: