【问题标题】:nginx redirect rule is redirecting everything to https even for other portsnginx 重定向规则将所有内容重定向到 https,即使对于其他端口也是如此
【发布时间】:2016-06-08 03:49:58
【问题描述】:

你好,我有这个配置

server {
    listen          82;
    server_name     myapp.mydomain.com;
    return          301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name myapp.mydomain.com
    # ... remain of the stuff here
}

在此之前,我有其他网站在端口中运行:80、3000 等...现在当我访问 http://myapp.mydomain.com 时会自动将我重定向到我的应用程序(因为我正在调用端口 82)并且如果我尝试访问另一个应用程序在 3000 端口上运行,它也会尝试重写 https://myapp.mydomain.com:3000...如果我使用 ip,它会按预期工作(不是 ssl 部分)。

完整配置见:

https://gist.github.com/angvp/363f50ff8b8d345126adaf1595cd2523

有什么想法吗?

【问题讨论】:

  • 显示完整的 https 服务器块

标签: redirect ssl nginx https


【解决方案1】:

好的,在我开始挖掘之后,我的 nginx conf 中有这个:

add_header Strict-Transport-Security max-age=15768000;

这是一种安全措施,但这会导致所有子域即使在不同的端口上也会始终尝试 https .. 正确的方法应该是每个端口的每个虚拟主机都有不同的子域..

【讨论】:

    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 2014-10-06
    • 2017-06-03
    • 1970-01-01
    • 2012-05-17
    • 2017-07-24
    • 2015-09-30
    • 1970-01-01
    相关资源
    最近更新 更多