Nginx: could not build map_hash, you should increase map_hash_bucket_size: 64
Solution 1
map_hash_max_size
and map_hash_bucket_size
must be in http
context, i.e. outside of map
directive.
map_hash_max_size 262144;
map_hash_bucket_size 262144;
map $uri $new_uri {
include /etc/nginx/conf.d/redirects.map;
}
Solution 2
I put it on the top of the http {} and it worked. Don't put it outside http {}
Related videos on Youtube
Putnik
AWS Certified Solutions Architect-Associate AWS Certified SysOps Administrator-Associate 10+ years with Linux etc :) Feel free to contact me via LinkedIn https://www.linkedin.com/in/alexander-lutchko-11b556b7/
Updated on September 18, 2022Comments
-
Putnik almost 2 years
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.
-
Michael Hampton over 5 yearsHow does your answer differ from the existing answer?
-
Michael Hampton over 5 yearsWell, having it twice in your config causes that problem.
-
tread over 5 yearsYip. Another reason why it is better to put this setting in the main nginx config.
-
Kevin Nguyen over 5 yearsI set up right above the map but still got the same error. It's really weird.
-
Alexey Ten over 5 years@KevinNguyen what error?
-
Kevin Nguyen over 5 yearsNginx: could not build map_hash, you should increase map_hash_bucket_size: 64. I posted my answer btw.
-
Michael Hampton about 5 yearsIt is not obvious but it also needs to appear before the
map
directives. -
black sensei almost 3 years@AlexeyTen this solution works well in with nginx 1.16 but not with nginx 1.18.