跳到主要内容
版本:V2.2.0

配置示例

本页提供常见「中间件 × 证书格式」组合的完整配置示例。每个示例包含两部分:服务侧的证书挂载配置,以及 clmBot 的 config.yaml 安装点配置。

示例中的路径均为演示值,请替换为实际环境中的路径。字段含义参见 配置参考

nginx + PEM

服务侧证书配置

在 nginx 站点配置中通过 ssl_certificatessl_certificate_key 挂载证书:

server {
listen 443 ssl;
server_name example.com;

ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;

location / {
root /usr/share/nginx/html;
}
}
信息

nginx 要求 ssl_certificate 文件中包含完整证书链(站点证书 + 中间证书)。因此 clmBot 安装点中建议将 ca_path 留空,clmBot 会把完整证书链合并写入 cert_path

clmBot 安装点配置

servers:
- id: nginx_pem
sub_code: <证书订阅号>
format:
pem:
cert_path: /etc/nginx/ssl/example.com.crt
ca_path: ""
key_path: /etc/nginx/ssl/example.com.key
after_script: |
nginx -t && nginx -s reload

Apache + PEM

服务侧证书配置

在 Apache 站点配置中通过 SSLCertificateFile 等指令挂载证书:

<VirtualHost *:443>
ServerName example.com

SSLEngine on
SSLCertificateFile /etc/httpd/ssl/example.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/example.com.key
SSLCertificateChainFile /etc/httpd/ssl/example.com.ca.crt
</VirtualHost>
信息
  • Apache 2.4.8 及以上版本也可以将证书链直接合并到 SSLCertificateFile 文件中,此时 SSLCertificateChainFile 可省略,clmBot 安装点中的 ca_path 相应留空。
  • 服务名按发行版选择:RHEL/CentOS 为 httpd,Debian/Ubuntu 为 apache2

clmBot 安装点配置

servers:
- id: apache_pem
sub_code: <证书订阅号>
format:
pem:
cert_path: /etc/httpd/ssl/example.com.crt
ca_path: /etc/httpd/ssl/example.com.ca.crt
key_path: /etc/httpd/ssl/example.com.key
after_script: |
apachectl configtest && systemctl restart httpd.service

Tomcat + JKS

服务侧证书配置

Tomcat 8.5 及以上版本在 conf/server.xml 中通过 SSLHostConfig 挂载 JKS keystore:

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="/opt/tomcat/conf/example.com.jks"
certificateKeystorePassword="<keystore密码>"
certificateKeyAlias="tomcat"
certificateKeyPassword="<私钥密码>"
type="RSA" />
</SSLHostConfig>
</Connector>

clmBot 安装点配置

servers:
- id: tomcat_jks
sub_code: <证书订阅号>
format:
jks:
path: /opt/tomcat/conf/example.com.jks
alias: tomcat
key_pass: <私钥密码>
store_pass: <keystore密码>
after_script: |
export JAVA_HOME=/usr/java
/opt/tomcat/bin/shutdown.sh
/opt/tomcat/bin/startup.sh
信息

若 Tomcat 由 systemd 管理,after_script 可简化为 systemctl restart <tomcat 服务名>

Tomcat + PEM

服务侧证书配置

Tomcat 8.5 及以上版本支持直接使用 PEM 文件,无需转换 JKS:

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeyFile="/opt/tomcat/ssl/example.com.key"
certificateFile="/opt/tomcat/ssl/example.com.crt"
certificateChainFile="/opt/tomcat/ssl/example.com.ca.crt"
type="RSA" />
</SSLHostConfig>
</Connector>

clmBot 安装点配置

servers:
- id: tomcat_pem
sub_code: <证书订阅号>
format:
pem:
cert_path: /opt/tomcat/ssl/example.com.crt
ca_path: /opt/tomcat/ssl/example.com.ca.crt
key_path: /opt/tomcat/ssl/example.com.key
after_script: |
export JAVA_HOME=/usr/java
/opt/tomcat/bin/shutdown.sh
/opt/tomcat/bin/startup.sh

自定义服务 + PFX

适用于以单文件证书包(PKCS#12)方式使用证书的服务,after_script 中可使用脚本模板变量

servers:
- id: app_pfx
sub_code: <证书订阅号>
format:
pfx:
path: /opt/app/ssl/example.com.pfx
key_pass: <PFX密码>
after_script: |
echo "certificate updated at {{ .DATETIME }}"
/usr/bin/systemctl restart example-app.service

验证

配置完成后,可手动触发一次更新验证整个流程:

./clm-bot-linux-amd64 update-certificate

确认证书文件已更新、服务已重载且新证书生效后,再按 证书更新方式 配置自动更新。