module geoip2 with map directive

R
  • 21 Jan '23
Hi list, I'm trying to block some countries to prevent access to three
applications from my app server, the problem is that the list is large
and I want to separate them into a separate file.

I'm using the geoip2 module and when I add the maps directive and make
an include to specify the file it doesn't work.

part of my nginx.conf

map $geoip2_data_country_code $allowed_country {
   default yes;
    include /etc/nginx/conf.d/geo_country.conf;
    }

conf.d/geo_country.conf

NI no; #Nicaragua

nginx -t

nginx: [emerg] unknown directive "NI" in /etc/nginx/conf.d/geo_country.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed

Any ideas, how to do this?

-- 
rickygm

http://gnuforever.homelinux.com
F
  • 22 Jan '23
On Sat, Jan 21, 2023 at 04:34:26PM -0600, Rick Gutierrez wrote:

Hi there,

> I'm using the geoip2 module and when I add the maps directive and make
> an include to specify the file it doesn't work.

I'm pretty sure that this "include" line works, but...

> part of my nginx.conf
> 
> map $geoip2_data_country_code $allowed_country {
>    default yes;
>     include /etc/nginx/conf.d/geo_country.conf;
>     }

...I suspect that you have another line somewhere else like "include
/etc/nginx/conf.d/*.conf;", and this file is also included at that point
in the config, and its content is not valid there.

> nginx: [emerg] unknown directive "NI" in /etc/nginx/conf.d/geo_country.conf:1
> nginx: configuration file /etc/nginx/nginx.conf test failed
> 
> Any ideas, how to do this?

Rename this file (and change the include line) to something like
geo_country.map, so that the name does not match the other include
directive pattern in your config.

    f
-- 
Francis Daly        francis at daoine.org
R
  • 23 Jan '23
El sáb, 21 ene 2023 a las 19:16, Francis Daly (<francis at daoine.org>) escribió:
>
> On Sat, Jan 21, 2023 at 04:34:26PM -0600, Rick Gutierrez wrote:
>

> I'm pretty sure that this "include" line works, but...
>

Hi francis

> > part of my nginx.conf
> >
> > map $geoip2_data_country_code $allowed_country {
> >    default yes;
> >     include /etc/nginx/conf.d/geo_country.conf;
> >     }
>
> ...I suspect that you have another line somewhere else like "include
> /etc/nginx/conf.d/*.conf;", and this file is also included at that point
> in the config, and its content is not valid there.
>
> > nginx: [emerg] unknown directive "NI" in /etc/nginx/conf.d/geo_country.conf:1
> > nginx: configuration file /etc/nginx/nginx.conf test failed
> >
> > Any ideas, how to do this?
>
> Rename this file (and change the include line) to something like
> geo_country.map, so that the name does not match the other include
> directive pattern in your config.

francis Right now I'm singing the song "We are the champions" , It
worked perfectly, thanks for the help.

-- 
rickygm

http://gnuforever.homelinux.com