Nginx 配置 Strict-Transport-Security (HSTS) 指令
在 Nginx 的配置文件中,可以在 server 段或 http 段中添加 Strict-Transport-Security 指令。一般来说,建议在 http 段中添加,这样所有的 server 都会应用这个指令,保证网站的安全性。配置文件位置一般在 /etc/nginx/nginx.conf 或 /etc/nginx/conf.d/default.conf。
例如,在 http 段添加 Strict-Transport-Security 指令的配置如下:
http {
# ...其他配置
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains' always;
}
该指令表示强制浏览器使用 HTTPS 连接访问网站,并且缓存此设置 1 年(31536000 秒)。includeSubDomains 表示此指令也应用于网站的子域名。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/oiaN 著作权归作者所有。请勿转载和采集!