Closed spacedmonkey closed 4 years ago
It would be very nice to have cloudfront support.
I just started testing this plugin and I managed to get cloudfront working by modifying the get_s3_url function to return a CNAME. I'm not sure yet if it broke other functionality.
I'd like to see this too :+1:
So this is somewhat supported, I just haven't done a great job at documenting it. As @spacedmonkey pointed out, it's via the use of constant S3_UPLOADS_BUCKET_URL
.
For example:
define( 'S3_UPLOADS_BUCKET', 'my-bucket' );
define( 'S3_UPLOADS_BUCKET_URL', 'http://uploads.mydomain.com' );
uploads.mydomain.com
being a CDN domain. Using cloudfront you can also map to a subdirectory, for example on most of our stuff we have a single bucket for lots of sites, so we have something like:
define( 'S3_UPLOADS_BUCKET', 'hmn-uploads-eu/humanmade-production' );
define( 'S3_UPLOADS_BUCKET_URL', 'http://uploads.hmn.md' );
Whereby the CloudFront distribution is set to to forward to hmn-uploads-eu/humanmade-production
to uploads urls don't need the "humanmade-production" part.
I should also note, doing anything more complex / magic via filtering etc of the content, is not really part of s3-uploads. It just allows you a way to change the wp_upload_dir
URLs, rather than replacing of existing content etc. If you want that level of magic, then it should probably come from a CDN plugin, not s3-uploads.
This comment is exactly what I was looking for. This is a really great plugin. Keep up the good work @joehoyle and crew!
Is it possible to use tachyon with this plugin? It adds CDN support and does a better job with image sizes to boot.
Is it possible to use tachyon with this plugin? It adds CDN support and does a better job with image sizes to boot.
That's actually how we're running it in production, yeah. You'll need to run Tachyon itself (which can be partially run on Lambda) plus the plugin.
@joehoyle Per your comment above regarding these variables:
define( 'S3_UPLOADS_BUCKET', 'my-bucket' );
define( 'S3_UPLOADS_BUCKET_URL', 'http://uploads.mydomain.com' );
Does this cause the uploads to send through Cloudfront or for the linked files, within Wordpress's HTML, to use http://uploads.mydomain.com instead of http://mybucket.s3.amazonaws.com ?
@arankin Your URLs output on the page will reflect the bucket URL constant (but I believe only for new files uploaded after you change it). Imagine the ...s3.amazonaws.com
as simply the default for the bucket URL.
As for CloudFront, you'll need to configure it on that domain to point to your bucket; S3 Uploads doesn't set that up automatically.
@joehoyle Is this also the way with S3_UPLOADS_BUCKET_URL if you use a self hosted, S3 compatible storage?
Nevermind, saw #184
I am getting the following path:
https://cdn.test.com/wp-content/uploads/2018/02/bg-our-clients.png
Using the following settings:
USE_S3_UPLOADS=true
S3_UPLOADS_BUCKET="mybucket"
S3_UPLOADS_KEY="some-key"
S3_UPLOADS_SECRET="some-secret"
S3_UPLOADS_REGION="some-region"
S3_UPLOADS_BUCKET_URL="https://cdn.test.com"
My issue is the "wp-content' bit. Using those settings, the bucket is generating an /upload/ folder in the bucket as parent. How can I prevent it from adding the wp-content prefix?
The path https://cdn.test.com/uploads/2018/02/bg-our-clients.png
works as expected, but is not the one the site tries to use.
@cdvv7788 wp-content
is not being added by S3-Uploads I think, there's no code for that special path, and it's also not how we run S3 uploads. If you didn't resolve this, feel free to re-open.
Quote from cloudfront site
Basically cloudfront is amazon CDN for S3 / amazon products. Whenever using S3 in production / large scale, always better to use a CDN for speed. At the moment, you can kind of build your own support with the define
S3_UPLOADS_BUCKET_URL
. This is not documented, well supported and has any unit tests for it. It would be nice if it was documented and could easily be turned on and off. We could add filters on places where the current S3 url is outputted, like wp_get_attachment_url and the_content, so that the cdn functionality would be turned off on none production enviroments. This cdn functionality doesn't need to be limited to cloudfront, if it filters a url, then you could use the same filter for other cdns.Willing to work on this, if you people think it is a good idea...