Discussion:
nginx 1.11.5 'duplicate' map_hash_bucket_size error when geoip_country block used?
l***@ssl-mail.com
2016-10-22 16:30:21 UTC
Permalink
I have a working nginx/1.11.5 instance, with this in config

...
http(
...
134 map_hash_bucket_size 4096;

...
)
...

when I add geoip blocking

...
http (
+ geoip_country /var/lib/GeoIP/GeoIP.dat;
+ map $geoip_country_code $allowed_country {
+ default yes;
+ XX no; # some country
...
134 map_hash_bucket_size 4096;

...
)
...

config check now reports

nginx: [emerg] "map_hash_bucket_size" directive is duplicate in /etc/nginx/nginx.conf:134

simply commenting out

- map_hash_bucket_size 4096;
+ #map_hash_bucket_size 4096;

fixes the config error.

Why can't 'map_hash_bucket_size' be set in the presence of the geoip_country snippet?

Config error? Bug? other?
itpp2012
2016-10-22 16:42:40 UTC
Permalink
Syntax: map_hash_bucket_size size;
Default: map_hash_bucket_size 32|64|128;
Context: http

The err message is valid but may be misleading due to the places you used, a
dup msg does not indicate the valid context area.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,270480,270481#msg-270481
l***@ssl-mail.com
2016-10-22 17:29:29 UTC
Permalink
Post by itpp2012
Syntax: map_hash_bucket_size size;
Default: map_hash_bucket_size 32|64|128;
Context: http
The err message is valid but may be misleading due to the places you used, a
dup msg does not indicate the valid context area.
Sorry, but ... "Huh?"

'valid' context per your own post is "http", as well as docs

http://nginx.org/en/docs/http/ngx_http_map_module.html#map_hash_bucket_size

My snippet clearly shows its use in http().
Maxim Dounin
2016-10-24 12:20:34 UTC
Permalink
Hello!
Post by l***@ssl-mail.com
I have a working nginx/1.11.5 instance, with this in config
...
http(
...
134 map_hash_bucket_size 4096;
...
)
...
when I add geoip blocking
...
http (
+ geoip_country /var/lib/GeoIP/GeoIP.dat;
+ map $geoip_country_code $allowed_country {
+ default yes;
+ XX no; # some country
...
134 map_hash_bucket_size 4096;
...
)
...
config check now reports
nginx: [emerg] "map_hash_bucket_size" directive is duplicate in /etc/nginx/nginx.conf:134
simply commenting out
- map_hash_bucket_size 4096;
+ #map_hash_bucket_size 4096;
fixes the config error.
Why can't 'map_hash_bucket_size' be set in the presence of the geoip_country snippet?
Config error? Bug? other?
It's not relevant to geoip_country, but rather to the map{} block
before the map_hash_bucket_size directive. Something like

map $uri $foo {}
map_hash_bucket_size 4096;

is enough to trigger the error, as the map{} block requires some
hash bucket size to be set. And if it is not set when parsing a
map{} block, it is automatically configures bucket size to a
default value. An attempt to redefine bucket size later will
trigger the error, and this is what happens with the above
configuration.

The message is a bit misleading in this particular situation
as it is a generic one. Though the fact that the configuration is
rejected is correct: nginx can't use the value specified in the
map_hash_bucket_size directive, and hence it is expected to reject
the configuration.

An obvious solution would be to specify map_hash_bucket_size
before the map{} block, i.e.:

map_hash_bucket_size 4096;
map $uri $foo {}
--
Maxim Dounin
http://nginx.org/
l***@ssl-mail.com
2016-10-24 16:08:57 UTC
Permalink
Post by Maxim Dounin
It's not relevant to geoip_country, but rather to the map{} block
before the map_hash_bucket_size directive. Something like
map $uri $foo {}
map_hash_bucket_size 4096;
is enough to trigger the error, as the map{} block requires some
hash bucket size to be set. And if it is not set when parsing a
map{} block, it is automatically configures bucket size to a
default value. An attempt to redefine bucket size later will
trigger the error, and this is what happens with the above
configuration.
The message is a bit misleading in this particular situation
as it is a generic one. Though the fact that the configuration is
rejected is correct: nginx can't use the value specified in the
map_hash_bucket_size directive, and hence it is expected to reject
the configuration.
An obvious solution would be to specify map_hash_bucket_size
map_hash_bucket_size 4096;
map $uri $foo {}
Clearly explained, and the 'solution', of simply ordering the commands as above, works as promised.

Once you understand what's going on, "directive is duplicate in" actually makes sense.

Curious, did I miss this ^^ fact in the docs somewhere?

Obviously not critical, but a more clearly descriptive/relevant error would be nice ....

Thanks.

Loading...