简体   繁体   English

Laravel和AWS Cloudfront

[英]Laravel and AWS Cloudfront

I was researching and read a lot of articles on one specific topic but couldn't find relevant answers anywhere. 我正在研究和阅读很多关于某个特定主题的文章,但无法在任何地方找到相关答案。

However I'm doing some things as a fun/private project in Laravel and I wanted to use Amazon S3 storage. 但是我在Laravel做一些有趣/私人的项目,我想使用Amazon S3存储。 I have everything set up, and it's working, I'm able to upload images to S3 from my application using Laravel Filesystem, but what I'm trying to do is use CloudFront (I have this set up and working too, the cloudfront is serving files properly) for serving images and files. 我已经完成了所有设置,并且它正常工作,我可以使用Laravel Filesystem从我的应用程序上传图像到S3,但我想要做的是使用CloudFront(我已经设置并运行了,云端是正确提供文件)用于提供图像和文件。

Now my question is: How to integrate AWS CloudFront "urls" into Laravel? 现在我的问题是:如何将AWS CloudFront“urls”集成到Laravel中? I mean how to store CloudFront urls inside a Laravel application? 我的意思是如何在Laravel应用程序中存储CloudFront URL? How do I retrieve file urls (ie images) so I can display it inside my application. 如何检索文件网址(即图像),以便我可以在我的应用程序中显示它。 Do I store just file paths in a database and use "some specific way" to serve the full url or do I save the full AWS CloudFront urls in a database? 我是否只将文件路径存储在数据库中并使用“某种特定方式”来提供完整的URL,还是将完整的AWS CloudFront URL保存在数据库中?

How does this works at all? 这怎么样? Sorry if the question is stupid, but I just dived into Laravel and I'm pretty new there. 对不起,如果问题是愚蠢的,但我只是潜入Laravel,我在那里很新。

Set url to your cloudfront url in config/filesystems/s3 在config / filesystems / s3中将url设置为您的cloudfront URL

's3' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => 'http://xxx.cloudfront.net']

It works in L5.5 它适用于L5.5

You can use this package https://github.com/publiux/laravelcdn 您可以使用此软件包https://github.com/publiux/laravelcdn

Content Delivery Network Package for Laravel Laravel的内容交付网络包

The package provides the developer the ability to upload his assets (or any public file) to a CDN with a single artisan command. 该软件包使开发人员能够使用单个artisan命令将其资产(或任何公共文件)上载到CDN。 And then it allows him to switch between the local and the online version of the files. 然后它允许他在本地和在线版本的文件之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM