I'm moving an old website to a new nginx based host. To preserve the URL (which completely changed) I have a file that lists the mapping. I want to use it with map module.
Inside /etc/nginx/nginx.conf http{ ... }
I refer to PERL and the lowercase function:
#Include PERL and have a function for lowercasing the incoming URL
perl_modules perl/lib;
# function to lowercase incoming strings like the URL
perl_set $uri_lowercase 'sub {
my $r = shift;
my $uri = $r->uri;
$uri = lc($uri);
return $uri;
}';
My site configuration, which is in the file /etc/nginx/sites-enabled/notessensei
(Thx Alexey to point that out) looks like:
server {
listen www.notessensei.com:80;
root /home/stw/www;
index index.html;
server_name www.notessensei.com notessensei.com;
location / {
map $uri_lowercase $new {
include /home/stw/www/blognginx.map;
}
if ($new) {
rewrite ^ $new redirect;
}
}
error_page 404 /blog/404.html;
}
The mapping file blognginx.map
looks like this:
/blog/d6plinks/shwl-6bv35s /blog/2005/04/garbage-in-.html;
/blog/d6plinks/shwl-6c6ggp /blog/2005/05/just-me.html;
/blog/d6plinks/shwl-6c6gh4 /blog/2005/05/it-is-quotmake-your-own-caption-quot-time.html;
/blog/d6plinks/shwl-6c997j /blog/2005/05/big-business-wwjd.html;
/blog/d6plinks/shwl-6ca5qb /blog/2005/05/domino-on-solaris-anyone.html;
/blog/d6plinks/shwl-6ce65j /blog/2005/05/going-places-vietnam.html;
/blog/d6plinks/shwl-6ce6c9 /blog/2006/02/umsys-as-old-as-unix-sort-of.html;
for about 1300 lines. When I do a service nginx configtest
I get a fail. When I don't use the include
statement I get an OK. Now I have 2 questions:
- Is there a way to get a more verbose error, one that tells me what is wrong and where?
- What is wrong? Do I need to change the content of the include file? Do I need to move the section?
Help is very much appreciated.
map
directive must be immediate childhttp
block.In your case, you must place it beside
server
block, because you custom config file is included right insidehttp
block in nginx.conf.I figured it out, thx to Alexey's pointers. There was a 4 fold problem:
service nginx configtest
tells less thannginx -t
, again Alexey pointed me thereNow my
/etc/nginx/nginx.conf
has 2 additional lines in thehttp {}
section:and the
/etc/nginx/sites-enabled/notessensei
file looks like this:If you want to see it in action, pick any blog entry from wissel.net and apply the uri part to notessensei.com - works like a charm with > 1200 entries.