点击小眼睛开启蜘蛛网特效

Let's Encrypt:centos7、nginx使用Certbot申请SSL证书,为站点添加https访问

前言

Https访问已经是大势所趋,在本站已经加入https之后,重新购置了一台服务器为私有云网盘添加https访问。本文主要记录在一台全新机子上安装nginx并利用certbot申请证书的过程。

过程

申请SSL证书前首先你的网站使用nginx并且可以正常运行,并且nginx使用conf文件为默认conf文件,关于nginx的安装配置请看这个链接,certbot申请命令的网站在此:https://certbot.eff.org/lets-encrypt/centosrhel7-nginx,选择合适的平台,进行相关命令。

需要注意因为安装certbot前需要安装EPEL (Extra Packages for Enterprise Linux),安装命令:

https://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F

 

安装的时候一定要看是否安装成功,可能系统中已经存在不同版本因此在安装之前需要将之前的版本卸载之后再进行安装。

在安装后需要执行sudo certbot --nginx命令,如果配置文件不是默认文件则会发生错误。

另外确保nginx开启了ssl功能,如果在安装过程中没有顺便开启ssl功能,很有可能会出现以下错误:

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:37

那是因为没有nginx没有开启ssl功能,执行以下步骤即可:

nginx开启ssl

进入源码包目录:

cd /usr/local/src/nginx-1.12.3

查看nginx原有的模块,看看是否存在ssl模块。

/usr/local/nginx/sbin/nginx -V

在configure arguments:后面显示的原有的configure参数如下:

--prefix=/usr/local/nginx --with-http_stub_status_module

那么我们的新配置信息就应该这样写:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
配置完成后,运行命令运行上面的命令即可,等配置完

make

备份原有已安装好的nginx。

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止)。

cp ./objs/nginx /usr/local/nginx/sbin/

然后启动nginx,仍可以通过命令查看是否已经加入成功。

/usr/local/nginx/sbin/nginx -V

 

看到下面这个说明配置成功:
[root@localhost ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
  点赞
本篇文章采用 署名-非商业性使用-禁止演绎 4.0 国际 进行许可
转载请务必注明来源: https://oldpan.me/archives/lets-encrypt-centos7-nginx-certbot-ssl-guide

   关注Oldpan博客微信公众号,你最需要的及时推送给你。


发表评论

邮箱地址不会被公开。 必填项已用*标注

评论审核已启用。您的评论可能需要一段时间后才能被显示。