How to use CoralCDN to help reduce bandwidth usage / server resources

If you have noticed since several weeks ago (if i recall it correctly because i completely forgot since when i enabled this although it’s not really that far lol) when you visited this domain name, sometimes you’ll see .nyud.net request appended on reaper-x.com (like images.reaper-x.com.nyud.net) and if you’re wondering on why there are several request made to that nyud.net domain? then here in this post i’m going to explain it

So basically .nyud.net is a domain name used by CoralCDN (a free Content Delivery Network) that allows you (as a website owner) to utilize their CDN Service to serve your content directly from their servers. And in most case, usually CoralCDN is used by many site owners when their website that is hosted on small server / shared hosting got linked from many popular website such as Digg, Slashdot, Reddit, etc. to help them survive the effect (Check this wikipedia page for more info) … although it can be used for any other purpose as well … like for example if you host your site from your own computer that doesn’t have enough bandwidth to supply all your site visitors, or just simply want to reduce the load on your server, or perhaps just to save bandwidth :D

And so without further ado, here’s on how to use CoralCDN as your personal site saver :)

Note: This is tested on Apache Web Server 2.2, and also make sure to enable mod_rewrite and mod_headers before continuing with this process

As for on how to enable mod_headers and mod_rewrite, just open your httpd.conf that is located in your Apache installation directory and locate this lines:

#LoadModule headers_module modules/mod_headers.so
#LoadModule rewrite_module modules/mod_rewrite.so

And remove the # character to enable them so it’ll looks like this

LoadModule headers_module modules/mod_headers.so
LoadModule rewrite_module modules/mod_rewrite.so

But of course if you choose to not build Apache modules as shared / DSO modules that can be toggled (static modules compile), then you’ll need to compile the modules first

Anyway, let’s begin the process

Using CoralCDN to serve your static files such as images, javascript, etc

1. Let’s say you put your image files inside images directory, and so every request to your image files will look like http://www.example.com/images/blabla.jpg
2. Now you need to locate .htaccess file on your document root
3. Insert these lines into your .htaccess file to redirect all the requests made to that images directory to be served by CoralCDN and if you have reached your limit on CoralCDN, all the request will be reverted back to your site/server:

Header append X-Coral-Control "redirect-home"
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$
RewriteRule ^images/(.*)$ http://www.example.com.nyud.net/images/$1 [R,L]

Alternatively, if you prefer to make all requests made by your self to not get redirected to CoralCDN (so that mean all of your site visitors will be served by CoralCDN but not you), you can use these instead:

Header append X-Coral-Control "redirect-home"
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.0
RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$
RewriteRule ^images/(.*)$ http://www.example.com.nyud.net/images/$1 [R,L]

And replace

!^123\.456\.789\.0

with your IP Address

That’s it … and you’re done … now you can save your server resources and bandwidth by offloading all static images to CoralCDN, unless of course you want to completely offload your site to CoralCDN, which is described below

Using CoralCDN to serve all requests made to your site

1. Locate the Document Root of your site
2. Create (or edit) .htaccess file on your document root
3. Insert these lines

Header append X-Coral-Control "redirect-home"
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$
RewriteRule ^(.*)$ http://www.example.com.nyud.net/$1 [R,L]

And just like before if you want to exclude your self from being redirected to CoralCDN you can always add

RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.0

Before

RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$

But what if you get 500 Internal Server Error message after placing the above code? that means you haven’t enabled mod_headers and or mod_rewrite yet, or you mistype something … somewhere

p.s. Although it’s possible to use Conditional Check to make sure that even if you forget to enable mod_rewrite and mod_headers to not throw error message, but for this purpose i think it’s better not to use conditional check so you’ll know whether the redirection to CoralCDN is working or not … and if it’s not working because mod_headers and mod_rewrite not enabled, you’ll get a beautiful 500 Internal Server Error Message

p.p.s Be warned, there is a limit on CoralCDN (i’m not sure on how big/small the limits are) so whenever you’ve reached your limit you’ll get the amazing 403 Forbidden Error, but with the mod_headers placed when Coral return 403 error, all the requests will be reverted back to your site

Leave a comment

Comments

  1. Christian Louboutin Heels Apr 1, 2014 at 10:18 AM

    What’s up every one, here every one is sharing these kinds of knowledge, thus it’s pleasant to read this website, and I used
    to visit this webpage daily.

  2. reinhold schäfer Aug 13, 2012 at 12:11 AM

    i only setup a proxy in apache httpconfig or in browser :x.y.z.nyud.net:8080

  3. budflick Feb 5, 2012 at 1:56 AM

    sir, i installed the htaccess on a subdomain, with modification to the code

    Header append X-Coral-Control “redirect-home”
    RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
    RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$
    RewriteRule ^(.*)$ http://s.static.budflick.com/$1 [R,L]

    i tried to access now it showed up but i cant confirm if its already from coralcdn or still a normal link.

    any help to verify?

  4. Plopui Nov 30, 2011 at 6:48 PM

    Pay attention when you copy/paste the code from this website; there are no tabs on the code, so, you’ll get a 500 error even if you have mod_headers and mod_rewrite not enabled. Please correct this (ex.: “redirect-home”RewriteCond, you must put a tab between ” and RewriteCond).

    Thanks.

    • Reaper-XReaper-X Dec 1, 2011 at 7:34 AM

      I’m sorry about that one, because well previously i use code tag with br tag (on all posts that needs it) and recently (probably several weeks ago) i changed all the code tag (automatically) to pre tag and that results in the br tag not being displayed as new line

      Thanks for the report, fixed :)

  5. Mark Waters Mar 21, 2010 at 4:53 AM

    Thanks for documenting this.

    I am using it for our ZenPhoto Gallery.

    Wrote up details here :-
    http://www.zenphoto.org/support/topic.php?id=7154

    • Reaper-XReaper-X Apr 6, 2010 at 5:51 PM

      You’re very welcome Mark and i’m really sorry for late reply because i just recently moved to another city :)

  6. Darkened Linux Oct 2, 2009 at 9:49 PM

    I like your site! I never knew about it, lol.
    http://www.reaper-x.net/

Trackbacks/Pingbacks

  1. Gratis cdn service coral via subdomain til .nyud.net « we-post-tech
  2. How to optimize and speed up Wordpress - Reaper-X

To reduce spam, if you're posting comment for the first time, it'll be moderated first. And if they aren't spam, subsequent comments will appear automatically. Also you may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>