分享

升级至Laravel 5.7报错setTrustedProxies() must be of the type integer的处理

 中间件 2020-08-13
  报错信息如下:
Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Argument 2 passed to Symfony\Component\HttpFoundation\Request::
setTrustedProxies() must be of the type integer, array given, called in D:\phpStudy\Laravel5.5\vendor\fideloper\proxy\src\TrustProxies.php on line 54"

升级至Laravel 5.7报错setTrustedProxies() must be of the type integer的处理
查阅文档发现是由于Symfony HttpFoundation 的可信任代理功能发生了根本性的改变,需要调整中是间件。
打开 App\Http\Middleware\TrustProxies
将代码:
protected $headers = [
        Request::HEADER_FORWARDED => 'FORWARDED',
        Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
        Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
        Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
        Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
    ];
修改为:
protected $headers = Request::HEADER_X_FORWARDED_ALL;
再次测试正常。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多