Welcome! Log In Create A New Profile

Advanced

Best way to redirect non-CloudFront requests to CloudFront

May 03, 2012 09:05AM
A summary of what I want to do is to redirect requests for image URL's that don't come from Amazon's CloudFront service to CloudFront. This is because I'm using origin pull, but what the redirect to be done at the nginx level.

Obviously this won't work:

rewrite ^/(.*).(png|gif|jpg) http://abc.cloudfront.net/$1.$2

because CloudFront's original requests will be redirected to itself, and also because I've got some further rewriting going on for WordPress image uploads (such that /files/myimage.png will be redirected to a PHP script for some sites, so I need that redirect to still happen and the one above to be bypassed in those instances when CloudFront is trying to do it's original lookup).

What I want to do is basically say:

if ($remote_addr !~ "abc.cloudfront.net") {
rewrite ^/(.*).(png|gif|jpg) http://abc.cloudfront.net/$1.$2
}

but this isn't possible (as remote_addr is an IP that may change) and is probably inefficient. Is there a correct way to redirect everything to a hostname that doesn't come from the hostname itself efficiently?
Subject Author Posted

Best way to redirect non-CloudFront requests to CloudFront

WheresWardy May 03, 2012 09:05AM

Re: Best way to redirect non-CloudFront requests to CloudFront

Alexandr Gomoliako May 03, 2012 09:18AM

Re: Best way to redirect non-CloudFront requests to CloudFront

WheresWardy May 03, 2012 09:44AM

Re: Best way to redirect non-CloudFront requests to CloudFront

WheresWardy May 08, 2012 05:53AM

Re: Best way to redirect non-CloudFront requests to CloudFront

Jonathan Matthews May 08, 2012 07:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 262
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