Appearance
部署SSL证书
此章节将引导您在成功生成证书后,如何部署到服务器并生效HTTPS加密。
Nginx
如果您使用的是Nginx,您可以按照以下步骤进行部署:
上传证书文件(
your_domain.key
、your_domain.pem
)到服务器的指定目录,例如/etc/nginx/ssl
在您的nginx配置文件中添加以下内容:
nginx
ssl_trusted_certificate /etc/nginx/ssl/your_domain.pem;
ssl_certificate /etc/nginx/ssl/your_domain.pem;
ssl_certificate_key /etc/nginx/ssl/your_domain.key;
listen 443 ssl http2;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s ipv6=off;
resolver_timeout 5s;
- 检测Nginx配置是否正确
bash
nginx -t
- 重启Nginx服务
bash
nginx -s reload
Apache
- 上传证书文件(
your_domain.key
、your_domain.pem
)到服务器的证书目录,例如:
bash
/etc/apache2/ssl/
- 修改Apache的SSL配置文件(如
/etc/apache2/sites-available/default-ssl.conf
):
apache
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/your_domain.pem
SSLCertificateKeyFile /etc/apache2/ssl/your_domain.key
SSLCertificateChainFile /etc/apache2/ssl/your_domain.pem
</VirtualHost>
- 启用SSL模块和配置(如未启用):
bash
a2enmod ssl
a2ensite default-ssl
- 检测配置语法:
bash
apachectl configtest
- 重启Apache服务:
bash
systemctl restart apache2
Tomcat
- 将证书转换为PKCS12格式:
bash
openssl pkcs12 -export -in your_domain.pem -inkey your_domain.key -out your_domain.p12 -name "tomcat_ssl" -password pass:your_password
- 上传生成的
your_domain.p12
文件到服务器,例如:
bash
/opt/tomcat/conf/ssl/
- 修改
conf/server.xml
文件:
xml
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
SSLEnabled="true" maxThreads="200">
<SSLHostConfig>
<Certificate certificateKeystoreFile="/opt/tomcat/conf/ssl/your_domain.p12"
certificateKeystorePassword="your_password"
certificateKeystoreType="PKCS12"/>
</SSLHostConfig>
</Connector>
- 重启Tomcat服务:
bash
systemctl restart tomcat
其他
如果此文档没有能解决您的疑问,您可以联系我们。