One line script to minify js css directory using yuicompressor

February 11th, 2009

The default installation of WordPress use full version of css and javascript library. In order to minify all of these files, I wrote this bash script to minify all of them. There will be no progress bar while minifying, so be patient.

cd wordpress
find -H . -type f -writable  \( -name \*.css -o -name \*.js \)  \
-exec sh -c "yuicompressor {} -o /tmp/yui.tmp && mv /tmp/yui.tmp {}" \;

This will only work under POSIX system.
Findutils should be included in most popular Linux distros.
Yuicompressor can be downloaded from here.

Bookmark and Share  
 

Yejun Linux , , , , , , , ,

SimpleCDN CNAME Confusion

February 9th, 2009

I am using SimpleCDN to serve some static scripts and images of WordPress on my website.

Not like AWS CloudFront, Amazon’s CDN service, which only allows expiration date carried from S3 file meta. SimpleCDN supports fine tuning Expiration, P3P and gzip encoding through something called Pre-URL. Which look like these

http://s.mudy.info.simplecdn.net/
http://s.mudy.info-s1.simplecdn.net/
http://s.mudy.info-e7.simplecdn.net/

Here ‘-s1′ means special 1 with expire and gzip; ‘-e7′ means 10 years expire without gzip. And a lot more with different combo effects.

SimpleCDN also supports CNAME to any of these urls. Because there is not a lot document on how to use simplecdn. I mistakenly CNAMEed ’s.mudy.info’ to the first URL

s.mudy.info.simplecdn.net

Run my website through Yslow, I got a lot F score due to lack of expire headers and non-gzip on static files. I realize I have to use these different Pre-URLs in order to get http headers, so I substitute ’s.mudy.info’ in WordPress with ’s.mudy.info-s1.simplecdn.net’ or ’s.mudy.info-e7.simplecdn.net’. Originally very simple urls’ become long and urgly.

Due to some DNS setting error, I accidentally pinged 2 different SimpleCDN pre-urls. The results are 2 different IPs. I reallized I made another mistake today, these pre-urls are supposed to be used as CNAME to get different http headers and gzip encoding, because these hostname all has their own IPs. A quick testing I CNAME ’s.mudy.info’ to

s.mudy.info-s1.simplecdn.net

which gives nicely gzipped files with correct expiration settings.

This design is what I initially did not expect. Because traditional CDN usually use HTTP hostname to distinguish objects, so I normally would think I have to use different hostnames. However SimpleCDN use anycast , so they use same IP block on on all edge servers, which make it possible to use different IP addresses to distinguish requests.

Bookmark and Share  
 

Yejun Web , ,

Using tinydns wildcards with cautions

February 9th, 2009

Tinydns support wildcards. However I just made a mistake make my own website inaccessible.

I was pointing all subdomains to a single host including this website.

C*.mudy.info:nw.mudy.info:1200

It worked perfect fine, until today I encounter a website which requires myn...@blog.mudy.info to verify ownership. I know it should just working without any further settings, however to be nice I added an additional mx record to my Tinydns to explicitly indicates the mail host of blog.mudy.info

@blog.mudy.info::nw.mudy.info.:5:1200

After that my website become inaccessible. Apparently tinydns will stop looking into data once a matching name found, even though the record type does not match and there are better matching wildcards.

To fix this, I added another explicit A record.

+blog.mudy.info:66.246.138.44:1200

CNAME record will work as well.

Bookmark and Share  
 

Yejun Linux , , , ,

Correct way to password protect Cherokee webserver

February 8th, 2009

I have played Cherokee server on my personal blog a couple of days. I used it for some private file. Some directories need to be password protected. Initially I set it up in this way.

Incorrect password protection for Cherokee webserver

Incorrect password protection for Cherokee webserver

Then I tested against some static files, it obviously worked. However a couple days later, I realize the php script inside this directory was not protected at all including index.php. A rather easy fix, I added the same auth method to php handler as well. However as I add more stuff into my private directory, some of them require individual handler to work correct, so I added same http authentication method to all of them. It is really a pain to maintain such a long auth list, suddenly I realized I must have done this in a wrong way.

After digging into the cherokee document and cookbook, I find this simple solution to protect a whole directory.

  1. Add a directory rule which match the directory you want to protect.
  2. Set the handler to None in Handler tab
  3. Set authentication method in Security tab.
  4. Move this rule to the top and uncheck final.

Correct way to password protect cherokee webserver.

Correct way to password protect cherokee webserver.

That’s it.

Bookmark and Share  
 

Yejun Linux, Web , , ,

How to do http redirect on varnish

February 7th, 2009

There is no built in function to do redirecting in Varnish.  After googling around, here is the result.

Using error page of varnish to return an object with location header, since obj is not available within vcl_recv.

sub vcl_recv {
if (req.http.host ~ "^(www.)?mudy.info$")
{
error 302;
}
}
sub vcl_error {
if (obj.status == 302 && req.http.host ~ "^(www.)?mudy.info$")
{
set obj.http.Location = "http://blog.mudy.info/";
}
}

I am unsure whether there is a simpler way to verify the request, so I test the same condition again inside vcl_error.

If you want request url appended to redirection, you can use this instead.

set obj.http.Location = "http://blog.mudy.info" req.url;
Bookmark and Share  
 

Yejun Linux, Web , , , , ,