I need to use redirect map with quite a lot rules (2k+ lines, file size is ~200K)
I have the following settings in nginx:
map $uri $new_uri {
include /etc/nginx/conf.d/redirects.map;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
# redirects
if ($new_uri) {
rewrite ^ $new_uri permanent;
}
as described here and found here. The problem : configtest fails:
nginx: [emerg] could not build map_hash, you should increase map_hash_bucket_size: 64
I tried to increase map_hash_max_size and map_hash_bucket_size to quite crazy values:
map $uri $new_uri {
map_hash_max_size 262144;
map_hash_bucket_size 262144;
include /etc/nginx/conf.d/redirects.map;
}
but still have the same error (ending exactly with '64'). I selected those values so they are bigger than the file size. I made sure I'm editing live config by adding "blabla" and see 'unknown directive'
So, how those values should be set? There's not much details in the official doc, unfortunately.
map_hash_max_size
andmap_hash_bucket_size
must be inhttp
context, i.e. outside ofmap
directive.I put it on the top of the http {} and it worked. Don't put it outside http {}
Add to the top of the
http
block in the main configuration file (/etc/nginx/nginx.conf
):