Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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


To configure the application all you have to do is edit the config.yaml file, the following is a sample configuration file: # <== 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: '' # <== the domain which it is redirected *to*

  status: 301
  location: ''
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


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.