反向代理后面的Symfony端口重定向

Kea*_*eat 5 php proxy redirect symfony

我有一个使用FosUserBundle的Symfony 3.2应用程序(在端口8443上运行)。当匿名用户访问“ https:// [myurl] .com:8443 ”时,他们将重定向到“ https:// [myurl] .com:8443 / login ”以进行登录过程。访问应用程序时,此重定向工作正常,但现在,我们希望使用反向代理将客户的请求转发到应用程序。客户将使用标准的https端口443。

发生了以下情况:用户使用“ https://myurl.com ” 访问应用程序。
反向代理将请求转发到在端口8443 上托管应用程序的Web服务器(IIS)
。发出请求的用户重定向到“ https://myurl.com:8443/login ”,因为8443是仅在服务器端打开。

我在symfony中尝试了不同的解决方案,但无法使其工作:
-在symfony中Request::setTrustedProxies(array('123.456.78.89'));
设置反向代理:-set http_port/https_port in config.yml
-set$_SERVER['SERVER_PORT'] = 443;

关于如何解决这个问题的任何想法吗?

谢谢

Gor*_*Gor 2

打开以下文件:

web/app.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

    // or, if your proxy instead uses the "Forwarded" header
    // Request::HEADER_FORWARDED

    // or, if you're using AWS ELB
    // Request::HEADER_X_FORWARDED_AWS_ELB
);
Run Code Online (Sandbox Code Playgroud)

看:

“如何配置 Symfony 在负载均衡器或反向代理后面工作” http://symfony.com/doc/3.4/deployment/proxies.html