在CentOS下使用Let's Encrypt获取证书

在CentOS下使用Let’s Encrypt获取证书


环境

-CentOS 6.5
-Apache Tomcat 7.0.81
-Apache httpd 2.2.15
-Python 2.6.6

步骤

1.从Certbot中获取脚本文件,并将其设置成可执行

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

2.编写一个配置文件

可以为Let’s encrypt新建一个目录,我新建的目录位于/etc/letsencrypt/,并将配置文件存放于/etc/letsencrypt/config/demo.com.conf(改成自己的域名)中,内容如下所示:

domains = demo.com
rsa-key-size = 3072
email = [email protected]
text = True

authenticator = webroot
webroot-path = /var/www/html

其中的domain和email需要改成自己的域名以及用于从Let’s Encrypt接收证书信息的邮箱,rsa-key-size推荐使用2048或者3072。

3.配置本地网站

上面的authenticator代表Let’s Encrypt的认证方式,webroot代表Let’s encrypt会通过注册的域名访问本地服务器的方式进行认证,后面的webroot-path参数代表本地服务器的根地址。这里我使用的是httpd默认的根地址/var/www/html。
之后需要启动httpd服务器(certbot脚本不会自动启动本地服务器),使用httpd -k start命令,如果访问 http://localhost 成功则说明本地服务器已经成功启动。

4.获取证书

sudo ./certbot-auto -c /etc/letsencrypt/configs/demo.com.conf certonly

出现”Congratulations”即说明已经成功获取证书。如果之前出现失败,则有可能出现“Too many failed authentications recently”,此时需要检查之前的步骤,更正配置之后,间隔一段时间再重新获取。

5.配置证书

现在证书和私钥就位于/etc/letsencrypt/live/demo.com/目录下。
如果使用Tomcat 的Apr模式进行配置的话:

port = "443"
    protocol = "org.apache.coyote.http11.Http11AprProtocol"
    maxThreads = "150"
    SSLEnabled = "true"
    scheme = "https"
    secure = "true"
    clientAuth = "false"
    sslProtocol = "TLS"
    SSLCertificateFile = "/etc/letsencrypt/live/demo.com/cert.pem"
    SSLCertificateKeyFile = "/etc/letsencrypt/live/demo.com/privkey.pem"
    SSLCertificateChainFile = "/etc/letsencrypt/live/demo.com/chain.pem"
>

之后就可以安全的使用https了。

你可能感兴趣的:(密码学,tomcat,centos,https)