Thursday, November 17, 2011

Blog URL migration with GAE redirect with nginx rewrite

I am in the process of migrating a number of applications I used to run on my VPS onto the Google Apps framework, mostly because I am lazy. One such application was this blog. Creating and copying the blog entries across was simple enough, but I also wanted to incorporate my static pages. This would require configuring www.die.net.au and die.net.au to make to my home page on the blog. As an extra step I wanted my VPS server to have as little to do as possible. My plan was to get www.die.net.au hosted in the Google Application Engine service then simple do a rewrite for die.net.au on my VPS.

I created a very simple Go app for GAE mapped to www.die.net.au that redirected to my blogs home page.
package page_redirect

import (
        "http"
)

func init() {
        http.HandleFunc("/", root)
}

func root(w http.ResponseWriter, r *http.Request) {
        http.Redirect(w, r, "http://blog.die.net.au/p/home.html", 302)
}

All my VPS needed to do now was redirect web requests for die.net.au to www.die.net.au. This was easily achieved by added a simple server configuration to my nginx front end.
server {
    listen 80;
    server_name die.net.au;
    rewrite ^/(.*) http://www.die.net.au permanent;
}

And that's it. My blog has now been fully integrated into Google for them to spy on with my blessings.

No comments:

Post a Comment