3 Answers
3

A simple rack application which makes redirection of multiple domains a breeze.

Configuration

To configure the application all you have to do is edit the config.yaml file, the following is a sample configuration file:

cosmicvent.net: # <== This is the host name of the domain which you want to redirect
status: 302 # <== status code with which it is redirected, 302 for temporary redirects, 301 for permanent redirects
location: 'http://cosmicvent.com' # <== the domain which it is redirected *to*
'localhost:3030':
status: 301
location: 'http://cosmicvent.com:3030'

I'm not sure what the best option is in your case. I suppose that you could create a cron job that generates part of your nginx config and then reloads, but that seems like a dangerous hack to me.

Depending on how much load you are getting on the relative URLs, you could just have your application code fire off the redirects. For example, if you're using PHP, check the incoming URL to see if it is your redirect table, if it is, send back an HTTP redirect to the canonical URL.

One idea is to have a database (MySQL or what have you) table that you can populate with your redirects. Every hour or so, cron can fire off a script that will examine that table, see if there are new entries from the last time it ran, and then generate a new nginx config based on what it finds in that table.

I'd suggest using something like Ruby + ERB to get this done.

Afterwards, it can issue a reload against nginx to avoid service outages.