【问题标题】:Nginx on SSL (443)SSL 上的 Nginx (443)
【发布时间】:2012-11-27 02:00:15
【问题描述】:

我的目标是从端口 80 重定向到 443(强制 https),但无法首先获得有效的 https 配置。我收到 503 服务器错误,日志中没有任何内容。我查看了 SO 和 SF 上的所有帖子,但没有一个有效(X_FORWARDED_PROTO、X-Forwarded-For 标头没有区别。)。我在负载均衡器后面的 EC2 上,因此我不需要使用与 SSL 相关的指令,因为我已经在 ELB 上配置了我的证书。我正在使用 Tornado 作为 Web 服务器。

这是配置,如果有人有想法,谢谢!

http {
    # Tornado server
    upstream frontends {
        server 127.0.0.1:8002;
    }

server {
    listen 443;

    client_max_body_size 50M;

    root <redacted>/static;

    location ^~/static/ {
        root <redacted>/current;
        if ($query_string) {
            expires max;
        }
    }

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://frontends;
    }
}
}

【问题讨论】:

    标签: ssl https nginx


    【解决方案1】:

    嗯,有两个不同的任务:

    如果您需要将所有 http 流量重定向到 https,则需要在 nginx 中创建 http 服务器:

        server {
          listen 80; 
          server_name example.com;
          return       301 https://example.com$request_uri;
        }
    

    第二点,如果您的 SSL 在 ELB 终止,那么您根本不需要启用 ssl 的 nginx 服务器。只需将流量从 ELB 传递到您的服务器 80 端口即可。

    【讨论】:

    • 是的。我得到了重定向部分,工作正常。如前所述,当它达到 443 时,我得到了 503。
    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    • 2018-08-25
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    相关资源
    最近更新 更多