效果就是访问博客的时候出现一把小绿锁,更加安(好)全(看)。
实现步骤如下:
申请SSL证书
阿里云可以申请一年的免费证书,下载到本地
上传证书到服务器
scp [文件名] root@[ip地址]:/etc/nginx/cert
开启安全组443端口
配置命令
#本地git bash登陆阿里云
ssh -v root@【域名】
vi /etc/nginx/nginx.conf
修改文件后如下:
server {
listen 443;
ssl on;
server_name www.xuetao.co;
root /usr/share/nginx/html;
ssl_certificate /etc/nginx/cert/3010766_xuetao.co.pem;
ssl_certificate_key /etc/nginx/cert/3010766_xuetao.co.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;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html/blog;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/blog;
}
}
#重定向80端口的请求到443端口
server{
listen 80;
server_name www.xuetao.co;
rewrite ^(.*) https://www.xuetao.co$1 permanent;
}
重启
nginx -s reload