启用 OCSP Stapling 可以提高 HTTPS 连接的性能和安全性:
ssl_stapling on;:启用 OCSP Stapling。服务器会缓存并提供证书的 OCSP 响应,而不是让每个客户端单独请求证书颁发机构。ssl_stapling_verify on;:启用 OCSP Stapling 响应的验证,确保服务器提供的 OCSP 响应是有效的。
这样可以减少客户端的请求次数,加快连接速度,同时提高证书状态检查的安全性。
以下配置方法仅供参考,请根据自己的实际情况配置。
一、Nginx
在 Nginx 中开启 OCSP Stapling,可以按照以下步骤操作:
-
确保 Nginx 已编译并支持 OCSP Stapling。通常现代版本的 Nginx 都支持。
-
在你的 Nginx 配置文件中(通常是
/etc/nginx/nginx.conf或/etc/nginx/conf.d/your_site.conf),找到你的server块。 -
在
server块中添加以下配置:
server {
listen 443 ssl;
server_name your_domain.com;
ssl_certificate /path/to/your_certificate.crt;
ssl_certificate_key /path/to/your_certificate_key.key;
ssl_trusted_certificate /path/to/your_trusted_certificate_chain.crt;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# 其他配置
}
其中:
ssl_certificate指向你的 SSL 证书文件。ssl_certificate_key指向你的 SSL 证书密钥文件。ssl_trusted_certificate指向你的完整证书链文件(包括根证书和中间证书)。resolver和resolver_timeout用于指定 DNS 解析器,帮助验证 OCSP 响应。
- 保存配置文件,然后重新加载 Nginx 配置: sudo nginx -s reload
这样就启用了 OCSP Stapling。
二、Apache
在 Apache 中开启 OCSP Stapling,可以按照以下步骤操作:
-
确保 Apache 已编译并支持 OCSP Stapling。通常现代版本的 Apache 都支持。
-
打开你的 Apache 配置文件(通常是
/etc/httpd/conf/httpd.conf或/etc/apache2/sites-available/your_site.conf)。 -
在你的虚拟主机配置中添加以下指令:
<VirtualHost *:443>
ServerName your_domain.com
SSLEngine on
SSLCertificateFile /path/to/your_certificate.crt
SSLCertificateKeyFile /path/to/your_certificate_key.key
SSLCertificateChainFile /path/to/your_certificate_chain.crt
SSLUseStapling on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLStaplingCache "shmcb:/var/run/ocsp(128000)"
# 其他配置
</VirtualHost>
其中:
SSLCertificateFile指向你的 SSL 证书文件。SSLCertificateKeyFile指向你的 SSL 证书密钥文件。SSLCertificateChainFile指向你的完整证书链文件(包括根证书和中间证书)。SSLUseStapling启用 OCSP Stapling。SSLStaplingResponderTimeout设置 OCSP 响应的超时时间。SSLStaplingReturnResponderErrors设置是否返回 OCSP 响应错误。SSLStaplingCache设置 OCSP Stapling 的缓存位置和大小。
- 保存配置文件,然后重新加载 Apache 配置: sudo systemctl reload apache2
或 sudo systemctl reload httpd
这样就启用了 OCSP Stapling。
三、IIS
在 IIS 中启用 OCSP Stapling 可以通过以下步骤完成:
- 打开 IIS 管理器。
- 在左侧连接窗口中选择你的服务器名称。
- 在中间的功能视图中,双击 “SSL 设置”。
- 在右侧操作窗口中,点击 “高级设置”。
- 在弹出的对话框中,找到 “启用 OCSP Stapling” 选项并将其设置为 “True”。
- 点击 “确定” 保存设置。
完成以上步骤后,OCSP Stapling 就会在 IIS 上启用。