Rewritemap in nginx


#1

I am trying to implement the RewriteMap funcionality I am using
extensively in apache in some way with nginx.

In apache we use a dbm database where we store legacy urls (around
100.000) that we redirect to their new urls.

We have
RewriteMap oldlinks dbm:/etc/apache2/oldlinks.dbm
RewriteCond %{REQUEST_URI} .php$
[NC]
RewriteCond %{HTTP_HOST} ^(www)?([^.]+).
[NC]
RewriteCond ${lowercase:%2}$1 ^(.)$
RewriteCond ${oldlinks:%1|NONE} ^(http://.
)$
RewriteRule ^(.*php)$ %1
[NC,R=301,L]

Now I am trying to reimplement this functionality in the nginx. I have
tried to create a text file with my mappings and use
NginxHttpMapModule but so far without success.

I get these messages
Starting nginx: 2008/10/03 20:31:58 [emerg] 22017#0: could not build
the map_hash, you should increase either map_hash_max_size: 102400 or
map_hash_bucket_size: 128
I can keep increase the sizes but at a certain point nginx doesn’t
even start up any more.

Are there other options here?

Klaas Naaijkens


#2

Which version of nginx are u using?


#3

I have tried 0.7.17 and 0.5.37


#4

On Fri, Oct 03, 2008 at 08:52:48PM +0200, Klaas Naaijkens wrote:

RewriteCond %{HTTP_HOST} ^(www)?([^.]+).
I get these messages
Starting nginx: 2008/10/03 20:31:58 [emerg] 22017#0: could not build
the map_hash, you should increase either map_hash_max_size: 102400 or
map_hash_bucket_size: 128
I can keep increase the sizes but at a certain point nginx doesn’t
even start up any more.

It seems that nginx starts, but run too long. What does top show at
start ?

You may try

http {
map_hash_bucket_size 1024;
map_hash_max_size 102400;


#5

Yes, it got to 99% CPU before and it kept there for some time.

With map_hash_bucket_size 1024 it works fine now. I had increased
bucket_size before but I hadn’t realized I had to keep doubling it.

Thank you for your help.