Archive | February, 2011

Canonical Rewrite Rule For Nginx

Need to redirect from acme.com to www.acme.com with nginx? No problem … just add a virtual host declaration for the non-www that redirects like this: server { listen 80; server_name acme.com; rewrite ^/(.*) http://www.acme.com/$1 permanent; } Bookmark on Delicious Digg this post Recommend on Facebook share via Reddit Share with Stumblers Tweet about it Subscribe [...]

Need to redirect from acme.com to www.acme.com with nginx? No problem … just add a virtual host declaration for the non-www that redirects like this:

server {
  listen 80;
  server_name acme.com;
  rewrite ^/(.*) http://www.acme.com/$1 permanent;
}
View Comments Continue Reading →

Reverse Proxy With Content Rewrites

One of our clients is a school district that wanted to make content on http://www.khanacademy.org/ (KA) available to users without Youtube. The KA site uses a bit of javascript to test if the user’s browser can get to youtube and if not it servers videos from an different source. Unfortunately this was not working for [...]

One of our clients is a school district that wanted to make content on http://www.khanacademy.org/ (KA) available to users without Youtube. The KA site uses a bit of javascript to test if the user’s browser can get to youtube and if not it servers videos from an different source. Unfortunately this was not working for the client.

To solve the problem we setup mod_proxy as a reverse proxy. Then we used mod_headers, mod_filter and mod_substitute to rewrite the javascript going to client and force the use of the youtube alternative.

Here’s the apache config that does the content rewrite. It’s located in the reverse proxy virtual host:

# do not accept gzip - gzip bypasses filters
RequestHeader unset Accept-Encoding

# declare that content should be filtered through mod_substitute
FilterDeclare NOTUBE
FilterProvider NOTUBE SUBSTITUTE Content-Type $text/html
FilterChain +NOTUBE

# change the javacript test so that it always failes
Substitute "s|youtube.com/favicon.ico|youtube.com/nfavicon.ico|in"
View Comments Continue Reading →