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

I am in the situation to give our marketing department the opportunity to maintain their redirects by their own. Until now, they passed the information to the IT department and we maintained it for them in nginx.conf.

Some of these guys are quite familiar with redirections in IIS or even in apache but it is no option to give them direct access to the nginx configuration.

I see, that there is no nginx support for .htaccess files which I could give access to and I would also prefer not to grant write access to an conf-file that nginx includes. I expect, that our marketing will break our nginx setup within hours...

Is there a secure possibility without giving them access our the heart of our load balancer?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

There is no built in way to properly isolate the rewrite configuration like that. There are three approaches you could take.

Map module include

The map module allows you to include mappings from a separate file. Nginx still has to be reloaded after the file is changed, and the mapping file must be syntactically correct, but it does limit what can be done.

nginx.conf:

map $uri $new {
    include /etc/nginx/marketing.map;
}

if ($new) {
    rewrite ^ $new redirect;
}

marketing.map:

/about  /company/about-us;
~^/people/(?<person>.*)$    /company/people/$person;

Pre-process configuration

The first is to write a script which transform the redirects from some format which you define into nginx configuration. For example, given a list of space separated redirects:

/foo/(.*) /bar/$1

and a script:

#!/bin/sh
while read SOURCE DEST; do
    echo "rewrite $SOURCE $DEST permanent;
done < redirects.txt > redirects.conf

to form the following configuration:

rewrite /foo/(.*) /bar/$1 permanent;

You'd then want to run nginx -t on the entire configuration to check that it's valid before reloading.

On-the-fly processing

The second option is to use ngx_lua, ngx_perl or ngx_js to implement reading and processing your redirect configuration in nginx itself. For example, the rewrite_by_lua directive allows you to execute Lua code to construct a rewrite. You need to be careful about preformance however since you'll be interpreting code for every request.

share|improve this answer
    
The map module does provided a slightly restricted way to configure redirects. –  mgorven Oct 24 '12 at 22:36
    
The map method looks very promising! So, I will start writing a simple website to maintain the map-file. Thank you! –  Sascha Oct 26 '12 at 6:08
    
Sadly, at this point (2014 fall) the ngx_js project was last touched over two years ago. ngx_lua is very active and well maintained, however. –  Ville Sep 28 at 21:48

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.