[英]Symfony2 router returns absolute url with port 80
When calling: 致电时:
$this->get('router')->generate('...',array(),true)
To get an absolute URL from a controller I get a URL with default Port 80: https://subdomain.mydomain.com:80 要从控制器获取绝对URL,我会得到一个默认端口80的URL: https : //subdomain.mydomain.com :80
How can I get rid of the :80? 我怎么能摆脱:80? This only happens in production.
这只发生在生产中。 On my local machine I don't get the default port in the absolute URL.
在我的本地计算机上,我没有在绝对URL中获取默认端口。
Production environment uses a reverse proxy (nginx:443->varnish->apache:80) The local apache server port is 80 but should be the remote Port 443. 生产环境使用反向代理(nginx:443-> varnish-> apache:80)本地apache服务器端口为80但应该是远程端口443。
顺便说一句,这已经在Symfony 2.3.5中得到修复https://github.com/symfony/symfony/commit/65814bae27d6fdb9501a4efd07e6b980353d89bb
You should check: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/UrlGenerator.php#line-244 , it might be the cause of your problem. 你应该检查: https : //github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/UrlGenerator.php#line-244 ,这可能是你的问题的原因。
It's also possible it's a caching issue, try debugging using: 它也可能是一个缓存问题,尝试调试使用:
$this->context->getHttpPort() / ->getHttpsPort()
You can also fix this by defining the router context in the parameters.yml file like so: 您还可以通过在parameters.yml文件中定义路由器上下文来解决此问题,如下所示:
router.request_context.host: localhost:8181
router.request_context.scheme: http
router.request_context.base_url: /application/path
This will let you generate correct URLs when there is no web context, like in commands or cron jobs. 这将允许您在没有Web上下文时生成正确的URL,例如在命令或cron作业中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.