[英]Symfony port redirection behind reverse proxy
I have a Symfony 3.2 application (running on port 8443) using FosUserBundle. 我有一个使用FosUserBundle的Symfony 3.2应用程序(在端口8443上运行)。 When anonymous users access ' https://[myurl].com:8443 ', they are redirected to ' https://[myurl].com:8443/login ' for the login process. 当匿名用户访问“ https:// [myurl] .com:8443 ”时,他们会被重定向到“ https:// [myurl] .com:8443 / login ”以进行登录。 This redirection is working fine when accessing the application but now, we want to use a reverse proxy to forward the requests from customers to the application. 这种重定向在访问应用程序时工作正常但现在,我们希望使用反向代理将客户的请求转发给应用程序。 Customers would use standard https port 443. 客户将使用标准的https端口443。
What happens is the following : Users access the application with ' https://myurl.com '. 会发生以下情况:用户使用“ https://myurl.com ”访问该应用程序。
The request is forwarded by the reverse proxy to the web server (IIS) hosting the application on port 8443. 该请求由反向代理转发到在端口8443上托管应用程序的Web服务器(IIS)。
The user making the request is redirected to ' https://myurl.com:8443/login ' which does not work because 8443 is only opened server-side. 发出请求的用户被重定向到“ https://myurl.com:8443/login ”,这不起作用,因为8443仅在服务器端打开。
I tried different solutions in symfony but was not able to make it work : 我在symfony中尝试了不同的解决方案但是无法使其工作:
-set up the reverse proxy in symfony : Request::setTrustedProxies(array('123.456.78.89'));
- 在symfony中设置反向代理: Request::setTrustedProxies(array('123.456.78.89'));
-set http_port/https_port in config.yml
-set http_port/https_port in config.yml
-set $_SERVER['SERVER_PORT'] = 443;
-set $_SERVER['SERVER_PORT'] = 443;
Any idea on how can I solve this ? 关于如何解决这个问题的任何想法?
Thanks 谢谢
Open the following file: 打开以下文件:
web/app.php
Right after this line: 就在这一行之后:
$request = Request::createFromGlobals();
Insert this block: 插入此块:
// 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
);
See: 看到:
"How to Configure Symfony to Work behind a Load Balancer or a Reverse Proxy" http://symfony.com/doc/3.4/deployment/proxies.html “如何配置Symfony在负载均衡器或反向代理服务器后面工作” http://symfony.com/doc/3.4/deployment/proxies.html
In addition to @Gor I think you should also configure your proxy to add X-Forwarded headers. 除了@Gor之外,我认为您还应该配置代理以添加X-Forwarded标头。 In Nginx something like 在Nginx中有类似的东西
location / {
proxy_pass http://myurl:8443;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.