Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a dynamic list of redirects from a relative url on my site to some other absolute url:

my_website_url_1 --> other_website_url_1
...
my_website_url_N --> other_website_url_N

This list consists of several hundreds of entries and is changed a few times per day.

(Actual list is in the DB, but it can be in a text file or in whatever form comfortable.)

"My site" is an nginx server.

I'm looking for a robust solution to deploy redirect list changes to an nginx server without interrupting the service.

Any advice?

Replacing nginx with something else is an option.

share|improve this question

3 Answers 3

I wrote a small rack app a long time ago exactly for this purpose. You can check it out at http://github.com/minhajuddin/redirector
From the readme:


Redirector

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'
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.