Symfony 3中http标头之间的冲突

问题描述 投票:1回答:1

我有一个使用Symfony 3.2的应用程序,从昨天开始运行良好。当我尝试访问应用程序时,我有一个BadRequestHttpException,它告诉我在我的请求中有两个http标头冲突:FORWARDED和X_FORWARDED_FOR。

Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException (code: 
0):The request headers contain conflicting information regarding the origin 
of this request. at /home/biotekagee/gdpl/var/cache/prod/classes.php:4630, 

Symfony\\Component\\HttpFoundation\\Exception\\ConflictingHeadersException (code: 
0): The request has both a trusted \"FORWARDED\" header and a trusted 
\"X_FORWARDED_FOR\" header, conflicting with each other. You should either 
configure your proxy to remove one of them, or configure your project to 
distrust the offending one. at 
/home/biotekagee/gdpl/var/bootstrap.php.cache:1297

我注意到的事情:

  • 问题出现在生产环境中。使用dev(app_dev.php)时一切都很好
  • 所以我试着在app.php中找到问题,当我评论线$kernel = new AppCache($kernel)问题解决了。我想那个问题来自HttpCache
  • 我没有使用任何代理
  • 清除缓存根本没有用

我已经和Symfony合作了不到一年,我还是一个菜鸟,这个错误确实让我很紧张。我希望有人能够帮助我。

php symfony http-headers
1个回答
1
投票

我首先在app.php中添加了这一行来解决问题

Request::setTrustedHeaderName(Request::HEADER_FORWARDED, null);

不是一个好的解决方案...然后,我从Symfony 3.2更新到Symfony 3.3,问题似乎已经消失。

© www.soinside.com 2019 - 2024. All rights reserved.