检查unzip
yum install -y unzip
从github下载自动安装程序
wget https://github.com/certbot/certbot/archive/master.zip
解压
unzip master.zip
进入certbot-master文件夹
cd certbot-master
关闭nginx
systemctl stop nginx
查看 letsencrypt-auto 工具的用法
./letsencrypt-auto --help
安装ssl证书
./letsencrypt-auto certonly --nginx --email 123@qq.com -d www.domain.com
–email:自己的电子邮件
-d:自己的域名
certonly:表示只获取证书,不安装
注意将上面的邮箱和域名替换成自己的
安装完成后注意两个配置项(#1,#2),在下面需要添加这两个配置
修改nginx配置
vim /etc/nginx/nginx.conf
Nginx 支持 rewrite 功能。若您在编译时没有去掉 pcre,您可在 HTTP 的 server 中增加 rewrite ^(.*) https://$host$1 permanent;,即可将默认80端口的请求重定向为 HTTPS,即可实现全栈https。修改如下内容:
server {
listen 443;
#填写绑定证书的域名
server_name www.domain.com;
ssl on;
#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
root /var/www/www.domain.com;
index index.html index.htm;
#证书文件名称
#这里填写#1的内容
ssl_certificate 1_www.domain.com_bundle.crt;
#私钥文件名称
ssl_certificate_key 2_www.domain.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 / {
index index.html index.htm;
}
}
server {
listen 80;
#填写绑定证书的域名
server_name www.domain.com;
#把http的域名请求转成https
rewrite ^(.*)$ https://$host$1 permanent;
}
重启nginx
systemctl start nginx