网站http改https Let’s Encrypt 安装 续期教程 免费ssl证书Let’s Encrypt使用教程Certbot...

使用Certbot部署HTTPS
本文详细介绍了如何使用Certbot在CentOS 7上为Nginx服务器获取并配置Let's Encrypt SSL/TLS证书,包括三种安装方法及证书的自动续订流程。此外,还提供了解决重定向次数过多的问题及更换图片链接的方法。

Certbot项目地址https://certbot.eff.org/

一、安装

先选择你的web服务器程序和操作系统:

就会出来适合你的情况的安装教程。非常简单,就几步,用的是nginx,VPS系统是centos 7。

三种方式:

第一种:

yum install epel-release yum install certbot certbot certonly

yum install epel-release yum install certbot certbot certonly 运行这个会出来图形安装模式,需要输入域名信息、邮箱、网站目录等。我用这个没有成功。

第二种:

yum install epel-release certbot certonly --webroot -w /var/www/example -d example.com -d www.example.com

#/var/www/example是你的网站目录,example.com和www.example.com是你的域名。

yum install epel-release certbot certonly --webroot -w /var/www/example -d example.com -d www.example.com

#/var/www/example是你的网站目录,example.com和www.example.com是你的域名。 这个其实是和第一种方法是一样的。

第三种:我是用这个成功的

这个需要先停止nginx服务

service nginx stop certbot certonly --standalone -d example.com -d www.example.com

#example.com和www.example.com是你的域名

service nginx stop certbot certonly --standalone -d example.com -d www.example.com

#example.com和www.example.com是你的域名 运行这个肯定能生成证书。生成的位置位于/etc/letsencrypt/live/你的域名/ 目录下。记得备份下。

恢复nginx运行

service nginx start

service nginx start 下面开始配置nginx

我的配置文件如下供参考:

server { listen 443 ssl; #如果需要spdy也可以加上,lnmp1.2及其后版本都默认支持spdy,lnmp1.3 nginx 1.9.5以上版本默认支持http2 server_name www.8dlive.com 8dlive.com; ##这里是你的域名 index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/www.8dlive.com; #网站目录 ssl_certificate /etc/letsencrypt/live/8dlive.com/fullchain.pem; #前面生成的证书,改一下里面的域名就行 ssl_certificate_key /etc/letsencrypt/live/8dlive.com/privkey.pem; #前面生成的密钥,改一下里面的域名就行 ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m;

 include wordpress.conf;  #这个是伪静态根据自己的需求改成其他或删除
 #error_page 404 /404.html;
 location ~ [^/]\.php(/|$)
{
 # comment try_files $uri =404; to enable pathinfo
 try_files $uri =404;
 fastcgi_pass unix:/tmp/php-cgi.sock;
 fastcgi_index index.php;
 include fastcgi.conf;     #lnmp 1.0及之前版本替换为include fcgi.conf;
 #include pathinfo.conf;
}

 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
 expires 30d;
}

 location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log  /home/wwwlogs/www.8dlive.com.log;

} server { listen 80; server_name www.8dlive.com 8dlive.com; location /.well-known/ { add_header Content-Type 'text/plain;'; root /home/wwwroot/www.8dlive.com; } location / { return 301 https://www.8dlive.com$request_uri; } }

server { listen 443 ssl; #如果需要spdy也可以加上,lnmp1.2及其后版本都默认支持spdy,lnmp1.3 nginx 1.9.5以上版本默认支持http2 server_name www.8dlive.com 8dlive.com; ##这里是你的域名 index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/www.8dlive.com; #网站目录 ssl_certificate /etc/letsencrypt/live/8dlive.com/fullchain.pem; #前面生成的证书,改一下里面的域名就行 ssl_certificate_key /etc/letsencrypt/live/8dlive.com/privkey.pem; #前面生成的密钥,改一下里面的域名就行 ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m;

 include wordpress.conf;  #这个是伪静态根据自己的需求改成其他或删除
 #error_page 404 /404.html;
 location ~ [^/]\.php(/|$)
{
 # comment try_files $uri =404; to enable pathinfo
 try_files $uri =404;
 fastcgi_pass unix:/tmp/php-cgi.sock;
 fastcgi_index index.php;
 include fastcgi.conf;     #lnmp 1.0及之前版本替换为include fcgi.conf;
 #include pathinfo.conf;
}

 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
 expires 30d;
}

 location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log  /home/wwwlogs/www.8dlive.com.log;

} server { listen 80; server_name www.8dlive.com 8dlive.com; location /.well-known/ { add_header Content-Type 'text/plain;'; root /home/wwwroot/www.8dlive.com; } location / { return 301 https://www.8dlive.com$request_uri; } }

自动化更新 Certbot可以配置在过期之前自动续订证书。由于咱们加密证书持续90天,这是非常明智的利用此功能的优势。您可以通过运行该命令来测试你的证书自动更新:

certbot renew --dry-run 1 certbot renew --dry-run 如果出现一切正常,你可以通过添加一个安排自动更新的cron或者systemd运行以下工作:

certbot renew --quiet 1 certbot renew --quiet 或者手动直接运行这个命令来续期,我还没有试过。

二、后续

做完以上步骤,其实有时并不能成功,但不是步骤不对,以上安装证书,配置文件,都没问题,也许是你的网站或者主题有问题。我的就是配置完之后,打开网站始终显示重定向次数过多,我是先把主题改成wordpress的默认的主题,然后进行以上的操作,之后又重新上传了自己的主题,这样就没问题了。

还有一个问题,就是网站的图片链接肯定都是http打头的,要进数据库批量改一下原图片地址的为https,不然只要一个页面有图片,那么这个网页地址那就不会有小绿锁。处理步骤:

1、先去wordpress后台,设置那,把网站地址改成https开头的

2、进数据库,点到wp_posts这个表,点右边搜索,点下面的Find and replace这里查找那里输入http://www.8dlive.com/wp-content/uploads,替换那里输入https://www.8dlive.com/wp-content/uploads,按照自己的域名写。然后点执行,这样就把http开头的都替换成https了,进行以上操作前记得备份数据库。这样应该就完美了。

转载于:https://my.oschina.net/yomut/blog/1557226

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值