Letsencrypt/SSL Tomcat8 Ubuntu 16.04

Letsencrypt/SSL Tomcat8 Ubuntu 16.04

我遵循了互联网上的一些指南,但我现在卡住了,因为 none 他们告诉我要做的事情从现在开始有效。

我有 Ubuntu 16.04 和 Tomcat8。我已经在 Tomcat 的 webapps 中部署了一个应用程序,它在 http 上运行良好。然后我使用 letsencrypt 获取证书并在验证我的 Tomcat 设置后,它给了我 4 个 .pem 文件。

现在我不明白如何在 Tomcat/conf/server.xml 中 link/use 它们以便能够访问端口 443/8443 上的应用程序。当我使用非 root 用户安装 Tomcat-service 时,我已经为 443 设置了端口转发到 8443。我将 .pem 文件放入 Tomcat 的 conf 文件夹中,因此 server.xml 就在它们旁边。

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
           maxThreads="150" SSLEnabled="true" >
    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
    <SSLHostConfig>
        <Certificate certificateKeyFile="conf/privkey.pem"
                     certificateFile="conf/cert.pem"
                     certificateChainFile="conf/chain.pem"
                     type="RSA" />
    </SSLHostConfig>
</Connector>

这是我在 server.xml 文件中的当前设置,但它不起作用。预设也没有 "fullchain.pem" 的位置,我不知道我是否需要更改其中带有 "org.apache" 的行,因为我不知道它们实际做了什么。

提前致谢。我设法在 Windows 和 Ubuntu 上做了一个自签名证书,但是你总是收到这个不安全的警告。有人告诉我 letsencrypt 不会发生这种情况。

我会写下我是如何安装它的:

下载 certbot:

$ wget https://dl.eff.org/certbot-auto<br/>
$ chmod a+x certbot-auto

获取证书:

$ sudo /path/to/certbot-auto certonly --webroot -w /path/to/apache-tomcat-8.5/webapps/ROOT -d example.com

您的证书将下载到此文件夹中:“/etc/letsencrypt/live/YOUR_WEBSITE_HERE/”

像这样编辑 server.xml 中的 HTTPS 连接器

<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true">
  <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"/>
  <SSLHostConfig>
  <Certificate 
 certificateKeyFile="/etc/letsencrypt/live/YOUR_WEBSITE_HERE/privkey.pem" 
 certificateFile="/etc/letsencrypt/live/YOUR_WEBSITE_HERE/cert.pem" certificateChainFile="/etc/letsencrypt/live/YOUR_WEBSITE_HERE/chain.pem" 
 type="RSA" />
</SSLHostConfig>
</Connector>

Let's Encrypt 证书的有效期通常为 90 天,因此您需要定期更新证书。为此,将以下行添加到 crontab:

0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && ./path/to/certbot-auto renew

我还写了一篇关于它的博客post,您可以在这里找到它:https://www.gasimof.com/blog/enable-https-for-free-for-tomcat/