【问题标题】:Symfony router redirect to http on a https applicationSymfony 路由器在 https 应用程序上重定向到 http
【发布时间】:2017-12-28 13:52:19
【问题描述】:

我正在将我的应用程序从 https://mywebsite.com (1) 迁移到 https://otherwebsite.com (2) 该应用程序托管在不同的服务器上

下面的代码在 (1) 上运行良好,生成的 url 的方案是https。 (2) 上的相同代码生成带有http 方案的url

$filterUrl = $this->router->generate('liip_imagine_filter', $params, UrlGeneratorInterface::ABSOLUTE_URL);

路由定义是

<route id="liip_imagine_filter" path="/media/cache/resolve/{filter}/{path}" methods="GET">
        <default key="_controller">%liip_imagine.controller.filter_action%</default>
        <requirement key="filter">[A-z0-9_\-]*</requirement>
        <requirement key="path">.+</requirement>
</route>

Symfony 路由器的经典使用,您知道为什么在 (1) 我得到 https 和在 (2) 我得到 http 吗?

【问题讨论】:

    标签: symfony http routing


    【解决方案1】:

    由于您没有将 schemeshost 属性传递给路由 liip_imagine_filter,因此 UrlGenerator 使用当前请求的属性。

    问题是 PHP 从 web 服务器接收请求信息,有时它得到的不是你所期望的。可能有某种反向代理,比如 Nginx,它接受来自 Internet 的 HTTPS 请求并通过 HTTP 将它们转发到另一个 Nginx,最后 symfony 接收 HTTP 方案。

    要查明反向代理后面的 (2) 服务器是否创建 test.php 文件:

    <?php
    
    echo $_SERVER['REQUEST_SCHEME'];
    

    它将输出当前的请求方案。

    要设置 Symfony 在反向代理下工作,请阅读官方文档中的这篇文章:https://symfony.com/doc/current/deployment/proxies.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-17
      • 2023-03-28
      • 1970-01-01
      • 2016-05-26
      • 2011-04-28
      • 1970-01-01
      • 2017-05-16
      • 2020-05-09
      相关资源
      最近更新 更多