【问题标题】:Using Let's encrypt with Apache and Apache Tomcat使用 Let's encrypt 和 Apache 和 Apache Tomcat
【发布时间】:2021-04-30 07:26:21
【问题描述】:

在同一台机器上,Apache 在端口 80 上运行,Tomcat 在端口 8080 上运行。
Apache 包含 html;css;js;文件并调用 tomcat 服务。
基本上 exampledomain.com 调用 exampledomain.com:8080 来接收数据。
现在我使用 Let's Encrypt certbot 将协议从 http 升级到 https 以生成证书,该证书将由 certbot 每 3 个月更新一次。 Apache 在端口 443 上运行良好,但 Tomcat 仍然使用端口 8080,我可以使用相同的证书在端口 8443 上运行 tomcat 但是.. 为此,需要将证书转换为 Java Keystore。

我的问题是,如果我要转换证书,它将在 3 个月后过期,我需要再次将 certbot 生成的新证书转换为 Java 密钥库?

【问题讨论】:

    标签: apache ssl tomcat lets-encrypt


    【解决方案1】:

    是的,您必须在每次证书到期时转换证书。

    Tomcat 接受 .jks 和 .pfx 证书,您可以通过编写脚本轻松地在每次 certbot 生成新证书时自动转换,并使用 certbot 续订挂钩运行它。

    脚本:

    #!/bin/bash
    # Adjust these variables as necessary
    
    # Where you want to final PKCS12 file to be stored.
    CERT_PATH="/opt/app/certificate.pfx"
    
    # Password to encrypt the PKCS12 file.
    CERT_PW="ShoobyDooby"
    
    # Path to LE files, RENEWED_LINEAGE provided by CertBot
    PRIV_KEY_PEM="$RENEWED_LINEAGE/privkey.pem"
    CERT_PEM="$RENEWED_LINEAGE/cert.pem"
    CHAIN_PEM="$RENEWED_LINEAGE/chain.pem"
    
    # If there's already a .pfx file, back it up
    if [[ -f "$CERT_PATH" ]]; then
        now=`date +%Y-%m-%d-%T`
        mv $CERT_PATH $CERT_PATH.bak.$now
    fi
    
    # Le Conversion
    openssl pkcs12 -export -out $CERT_PATH -inkey $PRIV_KEY_PEM -in $CERT_PEM -certfile $CHAIN_PEM -password pass:$CERT_PW
    

    将此脚本放在 /etc/letsencrypt/renewal-hooks/deploy/auto_pfx.sh
    别忘了chmod! 如果脚本不可执行,它会被忽略。

    Automatic PKCS12 Conversion for Let's Encrypt Certificates

    【讨论】:

      【解决方案2】:

      答案是肯定的和否定的:

      • 是的,如果您想将证书保留为 PKCS12 或 JKS 格式,则必须在每次续订后进行转换,就像您的回答一样,

      • ,在任何受支持的 Tomcat 版本上都不需要转换为 PKCS12,但 7.0 除外(无论如何都会在两个月内达到使用寿命)。 Tomcat 8.5、9.0 和即将发布的 10.0 读取 PEM 编码证书没有问题,只需像这样配置:

      <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
                 SSLEnabled="true">
        <SSLHostConfig>
          <Certificate certificateKeyFile="/etc/letsencrypt/live/example.org/privkey.pem"
                       certificateFile="/etc/letsencrypt/live/example.org/cert.pem"
                       certificateChainFile="/etc/letsencrypt/live/example.org/chain.pem"
                       type="RSA" />
        </SSLHostConfig>
      </Connector>
      

      这适用于所有三种类型的连接器(NIO、NIO2 和 APR)。另一方面,APR 连接器从不支持 PKCS12 和 JKS 密钥库。

      【讨论】:

        猜你喜欢
        • 2016-12-24
        • 2022-06-21
        • 1970-01-01
        • 2018-04-23
        • 1970-01-01
        • 1970-01-01
        • 2022-01-06
        • 2012-08-22
        • 1970-01-01
        相关资源
        最近更新 更多