跳至主要内容

配置範例

本頁提供常見「中介軟體 × 憑證格式」組合的完整設定範例。每個範例包含兩部分:服務端的憑證掛載設定,以及 clmBot 的 config.yaml 安裝點設定。

範例中的路徑均為示範值,請替換為實際環境中的路徑。欄位含義請參閱 設定參考。

nginx + PEM​

服務端憑證設定​

在 nginx 站點設定中透過 ssl_certificate 和 ssl_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

確認憑證檔案已更新、服務已重新載入且新憑證生效後,再按 憑證更新方式 設定自動更新。