Install from these repository.
Here is example of usage for Humhub,
- Catfs caches any files you accessed through goofys, up to (Your_storage_size - 1) GB. (
-free:1G
option below.) - Assumes your php runs as uid=33 & gid=33 (
-uid 33 --gid 33
option below).
$ sudo goofys -o allow_other --file-mode 0666 --dir-mode 0777 --uid 33 --gid 33 --cache=-o:allow_other:--free:1G:/PATH/TO/MY/CATFS_CACHE MY_S3_BUCKET:MY_S3_DIRECTORY_FOR_UPLOAD /PATH/TO/MY/S3_BUCKET_MOUNTPOINT
goofys#MY_S3_BUCKET:MY_S3_DIRECTORY_FOR_UPLOAD /PATH/TO/MY/S3_BUCKET_MOUNTPOINT fuse allow_other,--file-mode=0666,--dir-mode=0777,--uid=33,--gid=33,--cache=-o:allow_other:--free:1G:/PATH/TO/MY/CATFS_CACHE 0 0
Then check /etc/fstab
with sudo mount -a
and mount | grep fuse
.
- Copy all
/PATH/TO/MY/HUMHUB/uploads
files into/PATH/TO/MY/S3_BUCKET_MOUNTPOINT
- Rename
/PATH/TO/MY/HUMHUB/uploads
to/PATH/TO/MY/HUMHUB/uploads_bak
- Make symbolic link
sudo ln -s /PATH/TO/MY/S3_BUCKET_MOUNTPOINT /PATH/TO/MY/HUMHUB/uploads
- All media traffic still delivered from your Server, not CDN (CloudFront)
- Need to output proper CF distribution URL.
- Override
/protected/humhub/modules/file/models/File.php
'sgetUrl()
.
- CloudFront has "Restrict viewer access" feature, can identify access from Guest or Humhub user, with
Signed cookie
.- Limit lifetime of the signed cookie with
DateLessThan
policy - You can also limit with
IpAddress
policy, but site will broken with iOS 15's "Private relay" feature.
- Limit lifetime of the signed cookie with
- But CloudFront itself can't check whether the access (from the Humhub user) has proper privilege for private post or community.
- Concept to solve: We may be able to use CloudFront functions or Lambda@Edge to validate access.
- Add JSON Web Token on all
/file/file/download
URLs and CF func / Lambda@Edge validate them. - Users are given short-time JWT string for every valid (privileged) user access. JWT is issued from your code on Humhub, So only their access are allowed on CloudFront distribution.
- Minor cons: If even as the post was move into private, JWT & the URL still Valid until JWT expires.
More cool concepts are welcome.
Distribute images from CF, without modifying Humhub, Using NGINX Rewrite
You don't need to modify
getUrl()
on Humhub, change config of your webserver./themes/YOUR_THEME/views/layouts/head.php
)if(Yii::$app->user->isGuest)
to get login status.Examples: Using NGINX Rewrite Rules
https://www.nginx.com/blog/creating-nginx-rewrite-rules/
/etc/nginx/site_enabled
./uploads
are synced in S3 & distributed fromhttps://YOUR_CLOUDFRONT_ALT_DOMAIN/
, using CloudFront's alternative domain name.Examples:
rewrite ^.*?uploads\/profile_image\/([0-9a-f\-]+)(\.[a-z]+).*?$ https://YOUR_CLOUDFRONT_ALT_DOMAIN/profile_image/$1$2 last;
rewrite ^.*?uploads\/profile_image\/banner\/([0-9a-f\-]+)(\.[a-z]+).*?$ https://YOUR_CLOUDFRONT_ALT_DOMAIN/profile_image/banner/$1$2 last;
rewrite ^.*?file\/file\/download.*?preview\-image.*?guid=([0-9a-f])([0-9a-f])([0-9a-f\-]+).*?$ https://YOUR_CLOUDFRONT_ALT_DOMAIN/file/$1/$2/$1$2$3/preview-image last;
rewrite ^.*?file\/file\/download\?guid=([0-9a-f])([0-9a-f])([0-9a-f\-]+).*?$ https://YOUR_CLOUDFRONT_ALT_DOMAIN/file/$1/$2/$1$2$3/file last;