我想阻止用户使用 http 访问我的网站。
相反,我想强制使用 https。
通常,我将我的网站托管在仅具有“强制 https”复选框的提供商处。
在这种情况下,我有自己的 Ubuntu (nginx) 服务器。
我想知道我是否也可以在整个服务器范围内强制执行 https,还是必须在 HSTS header 中使用预加载标志?
任何人都可以指向我描述如何使用我的配置解决此问题的文档吗?
谢谢!
最佳答案
通常你需要两个 server
阻止在纯 HTTP 端口上监听的将所有请求重定向到 HTTPS 的位置:
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/certificate;
ssl_certificate_key /path/to/privatekey;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
# all the other configuration
}
如果您还需要将所有非 www 域名请求重定向到 www one(反之亦然),请检查 this回答。
关于ubuntu - 可以普遍执行严格的运输安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67114012/