Chu*_*utt 5 https amazon-web-services amazon-elb laravel amazon-elastic-beanstalk
在我的新项目中,当我将应用程序部署到https://域时,所有内容{{ asset() }}
都{{ route() }}
将被提供服务http
(这会在浏览器中引起“混合内容”安全性问题)。
我将AWS与负载平衡的Elastic Beanstalk应用程序一起使用。
我已经尝试确保APP_URL
将其正确设置为https,并且我知道我可以使用secure_asset或forceScheme,但是我不必在以前的项目中执行此操作,并且我想了解原因。
我如何看待Laravel在哪里决定协议?我想找到问题的根源,而不是加以解决。
这是一个简单的陷阱。如果您使用的是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)
现在一切都很好。设置新项目时容易错过。