-1

我在 nginx https + varnish + apache http = 重定向循环中配置了 Symfony

我提出了路由方案以获取链接 https : ['https'] 但得到重定向循环,为什么?看起来 symfony 不仅使用 https 创建链接,而且在获取 http 时返回重定向 - 我需要 http 页面在清漆中缓存,但链接 https。

更新 1 当我在路由中没有放置架构并通过 https 运行页面时,几乎一切正常 - 没有

1 fos 路由它创建绝对 http 链接

2 liip 想象同样的情况

4

1 回答 1

1

如果在访问页面时尽管使用了 https,但仍重定向到 https,则原始协议不会被转发到处理响应的后端。

X-Forwarded-Proto在通过任何代理之前,应设置一个标头以包含原始协议。Symfony 应该尊重此标头并接受请求是安全的而不是重定向(如果适当,还可以将所有链接设置为 https:// url)

您需要配置 Apache(我假设它正在终止 https 连接并拥有证书)以设置此标头以匹配原始请求协议。

看起来您可能需要信任代理,然后 Symfony 才会遵守标头Symfony Docs for proxies

// public/index.php

// ...
$request = Request::createFromGlobals();

// tell Symfony about your reverse proxy
Request::setTrustedProxies(
    // the IP address (or range) of your proxy
    ['192.0.0.1', '10.0.0.0/8'],

    // trust *all* "X-Forwarded-*" headers
    Request::HEADER_X_FORWARDED_ALL
);
于 2018-08-29T08:12:05.073 回答