【问题标题】:HTTP used in location header instead of HTTPS位置标头中使用 HTTP 而不是 HTTPS
【发布时间】:2017-08-22 14:10:10
【问题描述】:

设置:

Nginx 作为反向代理,终止 https

位于 localhost:8080 的 Apache 将 Mailman 应用程序(管理员 gui)交付给 Nginx

当我在浏览器中输入确切的 URL 时,例如 https://lists.staging.xxx.de/mailman/ 完美运行。

当我输入 https://lists.staging.xxx.de/mailman(不带斜杠)或什至只输入 https://lists.staging.xxx.de/ 时,Apache RedirectMatch 会启动,并通过标头位置信息发回正确的 url - 但方案不正确,即“位置:http://lists.staging.xxx.de/mailman/

当我执行curl -L -v -s -o /dev/null localhost:8080 时,我会返回:Location: http://localhost:8080/mailman/

所以我得出结论: Nginx 正确地重写了主机,但不是方案。

所以,要么我必须更改 Nginx 的配置,因此它会重写标头(即方案),要么我必须让 Apache 意识到 - 即使 https 已终止 - 标头位置语句也应该包含 https。

感谢任何帮助!

Nginx 配置:

server {
listen xxx:443;

server_name lists.staging.xxx.de;

if ($host != lists.staging.xxx.de) {
       rewrite (.*) https://lists.staging.xxx.de$1 permanent;
} 

ssl on;
ssl_certificate  /srv/s-bliss/deployment/work/nginxmailman/lists.staging.xxx.de.crt;
ssl_certificate_key  /srv/s-bliss/deployment/work/nginxmailman/lists.staging.xxx.de.key;

location / {
    proxy_pass              http://127.0.0.1:8080;
    proxy_set_header        Host $http_host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect          off;
}

}

Apache 配置:

Listen 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
    ServerName lists.staging.xxx.de

    Alias /mailman/icons /usr/lib/mailman/icons
    <Directory "/usr/lib/mailman/icons/">
            AllowOverride None
            Require all granted
    </Directory>

    Alias /mailman/archives /var/lib/mailman/archives/public
    <Directory "/var/lib/mailman/archives/public/">
            AllowOverride None
            Options ExecCGI FollowSymLinks
            AddDefaultCharset off
            Require all granted
    </Directory>

    RedirectMatch ^/$ /mailman/
    RedirectMatch ^/mailman$ /mailman/
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/mailman/(archives|icons)
    RewriteRule ^/mailman/(.*) /usr/lib/mailman/cgi-bin/$1 [H=cgi-script]
    <Directory "/usr/lib/mailman/cgi-bin/">
            AllowOverride None
            Options ExecCGI
            DirectoryIndex listinfo
            Require all granted
    </Directory>

【问题讨论】:

  • 您可以尝试添加proxy_set_header X-Forwarded-Proto $scheme;。但这需要 Apache 在构建响应时使用它。
  • 嗨,Richard,感谢您的输入 - 但是我将如何让 Apache 使用这些信息?像这样的东西? SetEnvIf HTTP_X_FORWARDED_PROTO "^https$" HTTPS=on SetEnvIf HTTP_X_FORWARDED_PROTO "^http$" HTTPS=off

标签: apache nginx https reverse-proxy mailman


【解决方案1】:

我们的提供商提出了以下解决方案:

http://lists.staging.xxx.de/mailman/ https://lists.staging.xxx.de/mailman/;

有效!

更新: 标头现在已正确传递,但有效负载(正文)仍包含指向 http 版本的链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 2011-05-03
    相关资源
    最近更新 更多