Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm hosting assets on S3 with this kind of URL: http://cdn.site.com/image.jpg In my application I automatically serve versioned URL to force browser to download new files after the deployment: "/1.2.3/image.jpg"

In every deployment I would only like to overwrite older files. So I need a regexp in HAProxy to rewrite this:

1.2.3/image.jpg

into this:

http://cdn.site.com/image.jpg

The other question is: will HAProxy redirect the request (visible for user) or just do that in the 'back' so this redirection will be invisible.

Thanks in advance!

share|improve this question
add comment

1 Answer

Here's code to do that.

acl imagereq path_beg /image.jpg

reqrep ^Host:\ 1.2.3   Host:\ cdn.site.com if imagereq

But I don't think that's really what you want to do.

reqrep will have haproxy change where it gets the content it serves your user.

HOWEVER: If the user has to go all the way to your server, then you've already wasted most of the benefit of a good CDN. (good CDNs are closer to your users than you are, and your users win by being able to get some of your content from them instead of going all the way back to you)

When you use reqrep, you're just having haproxy pop out to the nearest CDN node to YOU instead of getting it from the server you maintain.

Ideally what you want to do is adjust your HTML to point directly at your CDN.

Take at look at view source for sites like facebook, etc. You'll see their littered with links to URLS like static.ak.fbcdn.net.

static.ak.fbcdn.net is an alias for static.ak.facebook.com.edgesuite.net. static.ak.facebook.com.edgesuite.net is an alias for a749.dsw4.akamai.net.

akamai is a well known CDN provider.

By explicitly putting your cdn content locations in your raw HTML, your user only has to grab your main HTML, and all other content will be directly loaded from a CDN (hopefully) nearer to your user than you are...

You could consider having haproxy send a redirect to the user pointing them at the CDN for the content. But as I said before, if the user has already come all the way to your front door, you're wasting a lot of the benefit of a CDN.

Good luck.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.