Welcome! Log In Create A New Profile

Advanced

location rewrite s3 files

Posted by geer 
location rewrite s3 files
June 22, 2016 04:04PM
Hi, I have problems solving below case:

All our files that are uploaded to our server are copied to an AWS s3 bucket automatically. This is a repeating process.

We want to delete the original files and rewrite the original urls in the generated html files hosted by nginx

original URL: https://localhost.com/images/sg_profilepics/949/56_output.jpg?t=-62169984000

to be replaced with: http://s3-bucket.aws.domain.com/images/sg_profilepics/949/56_output.jpg?t=-62169984000

1) How to capture the location?
2) How to rewrite the URL's?
3) Can we make the rewrite transparent to the users so they are not aware of the redirect to amazon?

Hope somebody can help because I tried everything but I cant seem to get it working... :-(
Re: location rewrite s3 files
June 22, 2016 04:17PM
I have created this until now:

location @s3_2 {
set $s3_bucket 's3-eu-west-1.amazonaws.com/imagegallery';
set $url_full '$1';
rewrite ^ https://$s3_bucket/$url_full last;
}

location ~ /images/sg_profilepics/(.*)$ {
try_files $uri @s3_2;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 217
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready