
教程
1、准备证书⽂档
下载并解压证书包,打开证书⽂档 Nginx ⽂件夹,内有多种证书⽂件,对应说明如下:your_domain.ca-bundle
证书链⽂件your_domain.crt / your_domain.pem
证书公钥,不同格式供选⽤your_domain.key / your_domain.rsa.key
证书私钥,不同格式供选⽤
2、上传证书⽂件
将所需证书⽂件上传服务器,推荐⽬录/etc/ssl/
3、修改站点配置⽂件
修改 Apache 站点配置⽂件,该⽂件⼀般位于/etc/apache2/sites-available/
⽬录下
请注意,本配置仅供参考,特殊情况下请结合服务器系统版本及 Web 环境具体情况调整修改。
<VirtualHost *:443>
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/your_domain.crt
SSLCertificateKeyFile /etc/ssl/your_domain.key
SSLCertificateChainFile /etc/ssl/your_domain.ca_bundle # 可选配置,补充证书链⽂件
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" # 可选配置,开启 HSTS
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 # 可选配置,禁⽤不安全的协议版本
SSLCipherSuite HIGH:!aNULL:!MD5:!3DES:!CAMELLIA:!PSK:!SRP:!DSS # 可选配置,设置强加密算法
SSLHonorCipherOrder On # 可选配置,使⽤服务器端的⾸选算法顺序
</VirtualHost>
如果需要强制开启 https 跳转,请在上述配置⽚段前,增加以下配置
<VirtualHost *:80>
ServerName your_domain
ServerAlias www.your_domain
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
4、保存配置⽂件,重启 Apache 或服务器,配置⽣效
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。