Laravel使用AWS不安全地提供资产

Chu*_*utt 5 https amazon-web-services amazon-elb laravel amazon-elastic-beanstalk

在我的新项目中,当我将应用程序部署到https://域时,所有内容{{ asset() }}{{ route() }}将被提供服务http(这会在浏览器中引起“混合内容”安全性问题)。

我将AWS与负载平衡的Elastic Beanstalk应用程序一起使用。

我已经尝试确保APP_URL将其正确设置为https,并且我知道我可以使用secure_assetforceScheme,但是我不必在以前的项目中执行此操作,并且我想了解原因。

我如何看待Laravel在哪里决定协议?我想找到问题的根源,而不是加以解决。

Chu*_*utt 8

这是一个简单的陷阱。如果您使用的是AWS,则需要更改配置。这非常简单,并且与往常一样,Laravel的文档提供了解决方案。你可以在这里阅读更多:

https://laravel.com/docs/5.6/requests#configuring-trusted-proxies

在此处输入图片说明

我要做的(作为一个AWS Elastic Beanstalk用户)需要编辑app/Http/Middleware/TrustProxies.php

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */
    protected $proxies = '*';

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_AWS_ELB;
}
Run Code Online (Sandbox Code Playgroud)

现在一切都很好。设置新项目时容易错过。

  • 感谢您提供有关信任代理的提示。我使用 https://github.com/fideloper/TrustedProxy,它运行良好。 (2认同)