ubuntu - 可以普遍执行严格的运输安全吗?

标签 ubuntu security nginx https hsts

我想阻止用户使用 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/

相关文章:

linux - 如何随着时间的推移监控进程的内存使用情况 - ubuntu

ubuntu - 在终结者终端模拟器中运行 Zsh 时修复 .zshrc 中的键设置(Home/End/Insert/Delete)

c# - 在ASP.Net核心中应用粒度权限限制

tomcat - 生产中的 Grails 3 Asset Pipeline 产生错误的 URL 和 404ing

nginx - 用于视频流平台的开源 CMS 和服务器

php - 在 Ubuntu 14.04 上安装后 Apache 2 错误和 phpmyadmin 不工作

linux - 使用绝对路径覆盖 exec 系统调用

php - 使用 PHP 静态文件加载器加载 CSS 样式时出现问题

angularjs - 使用 NginX 提供 Angular 应用程序

postgresql - psycopg2.OperationalError 致命 : role "ubuntu" does not exist