[GH-ISSUE #46] Add GeoIP module #45

Open
opened 2026-02-26 05:33:37 +03:00 by kerem · 125 comments
Owner

Originally created by @teodorch85 on GitHub (Jan 8, 2019).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46

Hi! As I am noob with nginx is it possible to enable the GeoIP module so we can limit access also by location?
https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-by-geoip/

Thank you!

Originally created by @teodorch85 on GitHub (Jan 8, 2019). Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46 Hi! As I am noob with nginx is it possible to enable the GeoIP module so we can limit access also by location? https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-by-geoip/ Thank you!
Author
Owner

@jc21 commented on GitHub (Jan 8, 2019):

Sounds doable. Makes sense to include with improvements in #38 as well.

<!-- gh-comment-id:452490155 --> @jc21 commented on GitHub (Jan 8, 2019): Sounds doable. Makes sense to include with improvements in #38 as well.
Author
Owner

@wuast94 commented on GitHub (Feb 21, 2019):

the geoip module is active by default so no worry. its just a bit of path mapping and edit config files :P

the main problem of geoip module is using legacy geoip databases that are deprecated.
from https://dev.maxmind.com/geoip/legacy/downloadable/
to https://dev.maxmind.com/geoip/geoip2/geolite2/ wich is using
maxmind databases

but the geoip module from nginx is using teh legacy databases. so i dont know if its an issue from nginx itselfs or from npm. it sounds nice to block countries etc but i thing nginx need to fix it first before this feature can addet by devs to the container or am i wrong ?
i wrote more to -> #78

<!-- gh-comment-id:465959079 --> @wuast94 commented on GitHub (Feb 21, 2019): the geoip module is active by default so no worry. its just a bit of path mapping and edit config files :P the main problem of geoip module is using legacy geoip databases that are deprecated. from https://dev.maxmind.com/geoip/legacy/downloadable/ to https://dev.maxmind.com/geoip/geoip2/geolite2/ wich is using maxmind databases but the geoip module from nginx is using teh legacy databases. so i dont know if its an issue from nginx itselfs or from npm. it sounds nice to block countries etc but i thing nginx need to fix it first before this feature can addet by devs to the container or am i wrong ? i wrote more to -> #78
Author
Owner

@jc21 commented on GitHub (Feb 25, 2019):

Yep I've found the legacy databases are not longer supplied anymore so everyone has to convert to geo2.

Seems it's trivial to add the new module: https://docs.nginx.com/nginx/admin-guide/dynamic-modules/geoip2/

Also the geolite databases need to be baked in to the docker image.

<!-- gh-comment-id:466833442 --> @jc21 commented on GitHub (Feb 25, 2019): Yep I've found the legacy databases are not longer supplied anymore so everyone has to convert to geo2. Seems it's trivial to add the new module: https://docs.nginx.com/nginx/admin-guide/dynamic-modules/geoip2/ Also the geolite databases need to be baked in to the docker image.
Author
Owner

@wuast94 commented on GitHub (Feb 25, 2019):

I think it should be better to make this possible over mounting the nginx dir to host system. So everyone can edit this as wanted (use other modules or databases)

And I think the geo2 module should be addet by nginx docker Mainter. Many modules are installed by defoult: https://github.com/nginxinc/docker-nginx/blob/master/stable/alpine/Dockerfile

<!-- gh-comment-id:467111139 --> @wuast94 commented on GitHub (Feb 25, 2019): I think it should be better to make this possible over mounting the nginx dir to host system. So everyone can edit this as wanted (use other modules or databases) And I think the geo2 module should be addet by nginx docker Mainter. Many modules are installed by defoult: https://github.com/nginxinc/docker-nginx/blob/master/stable/alpine/Dockerfile
Author
Owner

@jc21 commented on GitHub (Feb 25, 2019):

You can already do that if you want to. In any docker image there is no restriction in what you're mounting and where. Even though I bake in config or files you're always able to override them.

<!-- gh-comment-id:467215855 --> @jc21 commented on GitHub (Feb 25, 2019): You can already do that if you want to. In any docker image there is no restriction in what you're mounting and where. Even though I bake in config or files you're always able to override them.
Author
Owner

@corvy commented on GitHub (Apr 24, 2020):

I would really love this feature. :)

<!-- gh-comment-id:619022365 --> @corvy commented on GitHub (Apr 24, 2020): I would really love this feature. :)
Author
Owner

@ghallford commented on GitHub (Jul 9, 2020):

This would be awesome because in order to use this

Currently nginx fails with this error when I add the custom log format:

2020/07/09 16:36:21 [emerg] 3022#3022: unknown "geoip2_data_city_name" variable

I need the geoIP information to send to InfluxDB custom format:

log_format custom '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" $host "$http_user_agent" "$request_time" "$upstream_connect_time" "$geoip2_data_city_name" "$geoip2_data_country_code"';

<!-- gh-comment-id:656341485 --> @ghallford commented on GitHub (Jul 9, 2020): This would be awesome because in order to use [this](https://github.com/gilbN/geoip2influx) Currently nginx fails with this error when I add the custom log format: > 2020/07/09 16:36:21 [emerg] 3022#3022: unknown "geoip2_data_city_name" variable I need the geoIP information to send to InfluxDB custom format: > log_format custom '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" $host "$http_user_agent" "$request_time" "$upstream_connect_time" "$geoip2_data_city_name" "$geoip2_data_country_code"';
Author
Owner

@joggs commented on GitHub (Aug 17, 2020):

Looking forward to this!

<!-- gh-comment-id:675075287 --> @joggs commented on GitHub (Aug 17, 2020): Looking forward to this!
Author
Owner

@brokoler commented on GitHub (Nov 16, 2020):

Still missing and everything I'm waiting for! 👍

<!-- gh-comment-id:728293562 --> @brokoler commented on GitHub (Nov 16, 2020): Still missing and everything I'm waiting for! 👍
Author
Owner

@risiman commented on GitHub (Jan 31, 2021):

That sounds great to me

<!-- gh-comment-id:770366597 --> @risiman commented on GitHub (Jan 31, 2021): That sounds great to me
Author
Owner

@andyshutak commented on GitHub (Feb 25, 2021):

Likewise this will help massively in reducing attempted logons and bruteforcing on my network. Watching closely.

<!-- gh-comment-id:786121383 --> @andyshutak commented on GitHub (Feb 25, 2021): Likewise this will help massively in reducing attempted logons and bruteforcing on my network. Watching closely.
Author
Owner

@Br3b commented on GitHub (Mar 2, 2021):

Hi guys,
this would be great! I was trying to get the geoip module or to at least implement a kind of monitoring possibility for the ngxin proxy manager with telegraf and grafana. But my limited docker knowledge is just not enough.
I would appreciate if this feature would be available out of the box :)
Stay healthy!

<!-- gh-comment-id:789068896 --> @Br3b commented on GitHub (Mar 2, 2021): Hi guys, this would be great! I was trying to get the geoip module or to at least implement a kind of monitoring possibility for the ngxin proxy manager with telegraf and grafana. But my limited docker knowledge is just not enough. I would appreciate if this feature would be available out of the box :) Stay healthy!
Author
Owner

@rh535 commented on GitHub (Mar 31, 2021):

This would be great!

<!-- gh-comment-id:811535607 --> @rh535 commented on GitHub (Mar 31, 2021): This would be great!
Author
Owner

@danner26 commented on GitHub (Apr 15, 2021):

@jc21 any update? I would be happy to help develop on this if y'all need an extra hand in order to get it included.

<!-- gh-comment-id:820456756 --> @danner26 commented on GitHub (Apr 15, 2021): @jc21 any update? I would be happy to help develop on this if y'all need an extra hand in order to get it included.
Author
Owner

@mgutt commented on GitHub (Apr 19, 2021):

+1

<!-- gh-comment-id:822189672 --> @mgutt commented on GitHub (Apr 19, 2021): +1
Author
Owner

@phrogg commented on GitHub (Apr 26, 2021):

Is there any way, to do this without it implemented? If I can set it up manually I may be able to make an PR out of it.

<!-- gh-comment-id:826977620 --> @phrogg commented on GitHub (Apr 26, 2021): Is there any way, to do this without it implemented? If I can set it up manually I may be able to make an PR out of it.
Author
Owner

@mouseron commented on GitHub (Jul 20, 2021):

Checking in to see if how this is going. @jc21 is there any update please. It would be great to have this implemented please and thank you!

<!-- gh-comment-id:883203884 --> @mouseron commented on GitHub (Jul 20, 2021): Checking in to see if how this is going. @jc21 is there any update please. It would be great to have this implemented please and thank you!
Author
Owner

@jc21 commented on GitHub (Jul 20, 2021):

See #1202

<!-- gh-comment-id:883325951 --> @jc21 commented on GitHub (Jul 20, 2021): See #1202
Author
Owner

@mouseron commented on GitHub (Jul 20, 2021):

See #1202

Thanks and it's great to see there will be a V3! I wasn't aware.

It's not clear not me whether GeoIP2 will be part of this new version though... The closest statement I could find was "UI Configurable IP ranges for real_ip determination"

Will GeoIP2 be incorporated?

Thanks again!

<!-- gh-comment-id:883766673 --> @mouseron commented on GitHub (Jul 20, 2021): > See #1202 Thanks and it's great to see there will be a V3! I wasn't aware. It's not clear not me whether GeoIP2 will be part of this new version though... The closest statement I could find was "UI Configurable IP ranges for real_ip determination" Will GeoIP2 be incorporated? Thanks again!
Author
Owner

@Pacerino commented on GitHub (Sep 12, 2021):

@mouseron
Take a look at https://github.com/sherpya/geolite2legacy
and
https://www.miyuru.lk/geoiplegacy

<!-- gh-comment-id:917531420 --> @Pacerino commented on GitHub (Sep 12, 2021): @mouseron Take a look at https://github.com/sherpya/geolite2legacy and https://www.miyuru.lk/geoiplegacy
Author
Owner

@Pacerino commented on GitHub (Sep 12, 2021):

the geoip module is active by default so no worry. its just a bit of path mapping and edit config files :P

the main problem of geoip module is using legacy geoip databases that are deprecated.
from https://dev.maxmind.com/geoip/legacy/downloadable/
to https://dev.maxmind.com/geoip/geoip2/geolite2/ wich is using
maxmind databases

but the geoip module from nginx is using teh legacy databases. so i dont know if its an issue from nginx itselfs or from npm. it sounds nice to block countries etc but i thing nginx need to fix it first before this feature can addet by devs to the container or am i wrong ?
i wrote more to -> #78

Hey @wuast94 i was wondering how the geoip module is active by default when the openresty doesnt get compiled with the flag to enable the geoip module? It would be nice if you could explain in detail how you managed it. The anweres you've made arent detailed.

<!-- gh-comment-id:917698766 --> @Pacerino commented on GitHub (Sep 12, 2021): > > > the geoip module is active by default so no worry. its just a bit of path mapping and edit config files :P > > the main problem of geoip module is using legacy geoip databases that are deprecated. > from https://dev.maxmind.com/geoip/legacy/downloadable/ > to https://dev.maxmind.com/geoip/geoip2/geolite2/ wich is using > maxmind databases > > but the geoip module from nginx is using teh legacy databases. so i dont know if its an issue from nginx itselfs or from npm. it sounds nice to block countries etc but i thing nginx need to fix it first before this feature can addet by devs to the container or am i wrong ? > i wrote more to -> #78 Hey @wuast94 i was wondering how the geoip module is active by default when the openresty doesnt get compiled with the flag to enable the geoip module? It would be nice if you could explain in detail how you managed it. The anweres you've made arent detailed.
Author
Owner
<!-- gh-comment-id:917753804 --> @jc21 commented on GitHub (Sep 13, 2021): Should anyone want to look at adding the module: - https://github.com/NginxProxyManager/docker-nginx-full/blob/master/docker/Dockerfile - https://github.com/NginxProxyManager/docker-nginx-full/blob/master/scripts/build-openresty
Author
Owner

@ghost commented on GitHub (Oct 28, 2021):

Here some useful material to compile geoip2 in openresty
https://www.electrosoftcloud.com/en/compile-geoip2-in-openresty-and-how-to-use-it/

<!-- gh-comment-id:954051036 --> @ghost commented on GitHub (Oct 28, 2021): Here some useful material to compile geoip2 in openresty https://www.electrosoftcloud.com/en/compile-geoip2-in-openresty-and-how-to-use-it/
Author
Owner

@OuticNZ commented on GitHub (Oct 31, 2021):

Did this get progressed any? Or is it waiting for someone to pick it up?

<!-- gh-comment-id:955633718 --> @OuticNZ commented on GitHub (Oct 31, 2021): Did this get progressed any? Or is it waiting for someone to pick it up?
Author
Owner

@chaptergy commented on GitHub (Oct 31, 2021):

No, I don't think there is any progress, and I don't think there will come an official integration in v2 of npm, unless someone wants to get working on it and creates a PR.

<!-- gh-comment-id:955730036 --> @chaptergy commented on GitHub (Oct 31, 2021): No, I don't think there is any progress, and I don't think there will come an official integration in v2 of npm, unless someone wants to get working on it and creates a PR.
Author
Owner

@Pacerino commented on GitHub (Oct 31, 2021):

I've actually made my own custom version of it with geoIP in order to use it with loki and grafana.
https://github.com/Pacerino/docker-nginx-full
https://github.com/Pacerino/nginx-proxy-manager

The only think is that i've ported the CI to Drone. There is an error appearing if creating the container about missing deps. I've temporary fixed it by installing libgeoip1_1.6 manually with DPKG

wget http://ftp.de.debian.org/debian/pool/main/g/geoip/libgeoip1_1.6.12-7_amd64.deb
dpkg -i libgeoip1_1.6.12-7_amd64.deb

After a reboot of the container everything works.

This is a quick and dirty implementation of it and not the latest release the main repo. The Frontend is missing the Logo but everything works. I should merge into the latest release and trying to get rid of the missing dep and the logo.

<!-- gh-comment-id:955743241 --> @Pacerino commented on GitHub (Oct 31, 2021): I've actually made my own custom version of it with geoIP in order to use it with loki and grafana. https://github.com/Pacerino/docker-nginx-full https://github.com/Pacerino/nginx-proxy-manager The only think is that i've ported the CI to Drone. There is an error appearing if creating the container about missing deps. I've temporary fixed it by installing `libgeoip1_1.6` manually with DPKG ```bash wget http://ftp.de.debian.org/debian/pool/main/g/geoip/libgeoip1_1.6.12-7_amd64.deb dpkg -i libgeoip1_1.6.12-7_amd64.deb ``` After a reboot of the container everything works. This is a quick and dirty implementation of it and not the latest release the main repo. The Frontend is missing the Logo but everything works. I should merge into the latest release and trying to get rid of the missing dep and the logo.
Author
Owner

@firebowl commented on GitHub (Jan 1, 2022):

Does anyone care about a geoip2 implementation? It would be a real pity if you have to give up the security of geoip2 for the really great and convenient variant of NPM.

<!-- gh-comment-id:1003601029 --> @firebowl commented on GitHub (Jan 1, 2022): Does anyone care about a geoip2 implementation? It would be a real pity if you have to give up the security of geoip2 for the really great and convenient variant of NPM.
Author
Owner

@danner26 commented on GitHub (Jan 1, 2022):

I personally do.

On Sat, Jan 1, 2022, 13:58 firebowl @.***> wrote:

Does anyone care about a geoip2 implementation? It would be a real pity if
you have to give up the security of geoip2 for the really great and
convenient variant of NPM.


Reply to this email directly, view it on GitHub
https://github.com/jc21/nginx-proxy-manager/issues/46#issuecomment-1003601029,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AB6JNIY4BQSLDMNGMXLQ2YTUT5FEFANCNFSM4GOX4ASA
.
You are receiving this because you commented.Message ID:
@.***>

<!-- gh-comment-id:1003601979 --> @danner26 commented on GitHub (Jan 1, 2022): I personally do. On Sat, Jan 1, 2022, 13:58 firebowl ***@***.***> wrote: > Does anyone care about a geoip2 implementation? It would be a real pity if > you have to give up the security of geoip2 for the really great and > convenient variant of NPM. > > — > Reply to this email directly, view it on GitHub > <https://github.com/jc21/nginx-proxy-manager/issues/46#issuecomment-1003601029>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AB6JNIY4BQSLDMNGMXLQ2YTUT5FEFANCNFSM4GOX4ASA> > . > You are receiving this because you commented.Message ID: > ***@***.***> >
Author
Owner

@ghallford commented on GitHub (Jan 1, 2022):

I do as well!

⁣--
Geoff​

On Jan. 1, 2022, 2:03 p.m., at 2:03 p.m., Daniel Anner @.***> wrote:

I personally do.

On Sat, Jan 1, 2022, 13:58 firebowl @.***> wrote:

Does anyone care about a geoip2 implementation? It would be a real
pity if
you have to give up the security of geoip2 for the really great and
convenient variant of NPM.


Reply to this email directly, view it on GitHub

https://github.com/jc21/nginx-proxy-manager/issues/46#issuecomment-1003601029,

or unsubscribe

https://github.com/notifications/unsubscribe-auth/AB6JNIY4BQSLDMNGMXLQ2YTUT5FEFANCNFSM4GOX4ASA

.
You are receiving this because you commented.Message ID:
@.***>

--
Reply to this email directly or view it on GitHub:
https://github.com/jc21/nginx-proxy-manager/issues/46#issuecomment-1003601979
You are receiving this because you commented.

Message ID: @.***>

<!-- gh-comment-id:1003603372 --> @ghallford commented on GitHub (Jan 1, 2022): I do as well! ⁣-- Geoff​ On Jan. 1, 2022, 2:03 p.m., at 2:03 p.m., Daniel Anner ***@***.***> wrote: >I personally do. > >On Sat, Jan 1, 2022, 13:58 firebowl ***@***.***> wrote: > >> Does anyone care about a geoip2 implementation? It would be a real >pity if >> you have to give up the security of geoip2 for the really great and >> convenient variant of NPM. >> >> — >> Reply to this email directly, view it on GitHub >> ><https://github.com/jc21/nginx-proxy-manager/issues/46#issuecomment-1003601029>, >> or unsubscribe >> ><https://github.com/notifications/unsubscribe-auth/AB6JNIY4BQSLDMNGMXLQ2YTUT5FEFANCNFSM4GOX4ASA> >> . >> You are receiving this because you commented.Message ID: >> ***@***.***> >> > > >-- >Reply to this email directly or view it on GitHub: >https://github.com/jc21/nginx-proxy-manager/issues/46#issuecomment-1003601979 >You are receiving this because you commented. > >Message ID: ***@***.***>
Author
Owner

@Pl1997 commented on GitHub (Jan 17, 2022):

Hi, this would be great for me too !

<!-- gh-comment-id:1014313776 --> @Pl1997 commented on GitHub (Jan 17, 2022): Hi, this would be great for me too !
Author
Owner

@spiezmaestro commented on GitHub (Jan 29, 2022):

Hi, would like to have this as well!

<!-- gh-comment-id:1024966181 --> @spiezmaestro commented on GitHub (Jan 29, 2022): Hi, would like to have this as well!
Author
Owner

@scyto commented on GitHub (Feb 2, 2022):

I am new to NPM, seeing if it can replace my custom config.
I am glad to see this will be in v3.

I note despite someone saying the geoip modules are loaded in the base docker used for npm an nginx -V reveals this is not the case :-(

For now with v2 is there anyway to get the geoip modules working?
(i use them for my csustom log format)

I copied over ngx_http_geoip_module.so and tried loading it using /data/nginx/custom/root.conf
however i get the error
nginx: [emerg] "load_module" directive is specified too late in /data/nginx/custom/root.conf:2

I assume this is because this is placed at the of the root conf rather than in the main block?
Is there any other workaround?

(in v3 can we have standard support for modules using the normal /modules-enabled/50*.conf files method?)

ok i see how to get modules loaded in npm, i mapped a volume to /etc/nginx/modules

i am now caught in dependency loop of finding just the right modules, i guess because i need the resty version of ngx_http_geoip_module.so (version 1019009) i am unclear where i can get that from?

<!-- gh-comment-id:1027482038 --> @scyto commented on GitHub (Feb 2, 2022): I am new to NPM, seeing if it can replace my custom config. I am glad to see this will be in v3. I note despite someone saying the geoip modules are loaded in the base docker used for npm an nginx -V reveals this is not the case :-( For now with v2 is there anyway to get the geoip modules working? (i use them for my csustom log format) I copied over ngx_http_geoip_module.so and tried loading it using `/data/nginx/custom/root.conf` however i get the error `nginx: [emerg] "load_module" directive is specified too late in /data/nginx/custom/root.conf:2` I assume this is because this is placed at the of the root conf rather than in the main block? Is there any other workaround? ~~(in v3 can we have standard support for modules using the normal /modules-enabled/50*.conf files method?)~~ ok i see how to get modules loaded in npm, i mapped a volume to /etc/nginx/modules i am now caught in dependency loop of finding just the right modules, i guess because i need the resty version of ngx_http_geoip_module.so (version 1019009) i am unclear where i can get that from?
Author
Owner

@TehloWasTaken commented on GitHub (Mar 2, 2022):

I've actually made my own custom version of it with geoIP in order to use it with loki and grafana. https://github.com/Pacerino/docker-nginx-full https://github.com/Pacerino/nginx-proxy-manager

The only think is that i've ported the CI to Drone. There is an error appearing if creating the container about missing deps. I've temporary fixed it by installing libgeoip1_1.6 manually with DPKG

wget http://ftp.de.debian.org/debian/pool/main/g/geoip/libgeoip1_1.6.12-7_amd64.deb
dpkg -i libgeoip1_1.6.12-7_amd64.deb

After a reboot of the container everything works.

This is a quick and dirty implementation of it and not the latest release the main repo. The Frontend is missing the Logo but everything works. I should merge into the latest release and trying to get rid of the missing dep and the logo.

Hey, just tried to look at your custom repo's, but they're not public anymore, or deleted.
Do you still have these? I'd love to use these as I'd like to setup:
https://grafana.com/grafana/dashboards/12559

Thanks!

<!-- gh-comment-id:1057016139 --> @TehloWasTaken commented on GitHub (Mar 2, 2022): > I've actually made my own custom version of it with geoIP in order to use it with loki and grafana. https://github.com/Pacerino/docker-nginx-full https://github.com/Pacerino/nginx-proxy-manager > > The only think is that i've ported the CI to Drone. There is an error appearing if creating the container about missing deps. I've temporary fixed it by installing `libgeoip1_1.6` manually with DPKG > > ```shell > wget http://ftp.de.debian.org/debian/pool/main/g/geoip/libgeoip1_1.6.12-7_amd64.deb > dpkg -i libgeoip1_1.6.12-7_amd64.deb > ``` > > After a reboot of the container everything works. > > This is a quick and dirty implementation of it and not the latest release the main repo. The Frontend is missing the Logo but everything works. I should merge into the latest release and trying to get rid of the missing dep and the logo. Hey, just tried to look at your custom repo's, but they're not public anymore, or deleted. Do you still have these? I'd love to use these as I'd like to setup: https://grafana.com/grafana/dashboards/12559 Thanks!
Author
Owner

@Pacerino commented on GitHub (Mar 2, 2022):

Im back at Friday and can take a Look. Ive probably deleted it.

Von meinem iPhone gesendet

Am 02.03.2022 um 14:52 schrieb Tehlo @.***>:



I've actually made my own custom version of it with geoIP in order to use it with loki and grafana. https://github.com/Pacerino/docker-nginx-full https://github.com/Pacerino/nginx-proxy-manager

The only think is that i've ported the CI to Drone. There is an error appearing if creating the container about missing deps. I've temporary fixed it by installing libgeoip1_1.6 manually with DPKG

wget http://ftp.de.debian.org/debian/pool/main/g/geoip/libgeoip1_1.6.12-7_amd64.deb
dpkg -i libgeoip1_1.6.12-7_amd64.deb

After a reboot of the container everything works.

This is a quick and dirty implementation of it and not the latest release the main repo. The Frontend is missing the Logo but everything works. I should merge into the latest release and trying to get rid of the missing dep and the logo.

Hey, just tried to look at your custom repo's, but they're not public anymore, or deleted.
Do you still have these? I'd love to use these as I'd like to setup:
https://grafana.com/grafana/dashboards/12559

Thanks!


Reply to this email directly, view it on GitHubhttps://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1057016139, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFJKPD3HOXB3UX2342N4X63U556DTANCNFSM4GOX4ASA.
You are receiving this because you commented.Message ID: @.***>

<!-- gh-comment-id:1057108034 --> @Pacerino commented on GitHub (Mar 2, 2022): Im back at Friday and can take a Look. Ive probably deleted it. Von meinem iPhone gesendet Am 02.03.2022 um 14:52 schrieb Tehlo ***@***.***>:  I've actually made my own custom version of it with geoIP in order to use it with loki and grafana. https://github.com/Pacerino/docker-nginx-full https://github.com/Pacerino/nginx-proxy-manager The only think is that i've ported the CI to Drone. There is an error appearing if creating the container about missing deps. I've temporary fixed it by installing libgeoip1_1.6 manually with DPKG wget http://ftp.de.debian.org/debian/pool/main/g/geoip/libgeoip1_1.6.12-7_amd64.deb dpkg -i libgeoip1_1.6.12-7_amd64.deb After a reboot of the container everything works. This is a quick and dirty implementation of it and not the latest release the main repo. The Frontend is missing the Logo but everything works. I should merge into the latest release and trying to get rid of the missing dep and the logo. Hey, just tried to look at your custom repo's, but they're not public anymore, or deleted. Do you still have these? I'd love to use these as I'd like to setup: https://grafana.com/grafana/dashboards/12559 Thanks! — Reply to this email directly, view it on GitHub<https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1057016139>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFJKPD3HOXB3UX2342N4X63U556DTANCNFSM4GOX4ASA>. You are receiving this because you commented.Message ID: ***@***.***>
Author
Owner

@jgramling17 commented on GitHub (Oct 3, 2022):

Any updates on this? I think making it an optional config through env variables or something similar wouldn't sacrifice simplicity for basic use cases.

<!-- gh-comment-id:1265747284 --> @jgramling17 commented on GitHub (Oct 3, 2022): Any updates on this? I think making it an optional config through env variables or something similar wouldn't sacrifice simplicity for basic use cases.
Author
Owner

@benisai commented on GitHub (Jan 10, 2023):

I'm also interested in this.

<!-- gh-comment-id:1376653704 --> @benisai commented on GitHub (Jan 10, 2023): I'm also interested in this.
Author
Owner

@hellcry37 commented on GitHub (Mar 10, 2023):

This geoip missing is what is stopping me to use this against the actual nginx.
My nginx confs work great what I miss is the actual ease of use of this software. But without geoip to protect my stuff and let only a country to access my websites and whitelist only some ip from the countrys i do not want to acess my stuff there is no way this is viable. Thanks for your consideration

<!-- gh-comment-id:1463557890 --> @hellcry37 commented on GitHub (Mar 10, 2023): This geoip missing is what is stopping me to use this against the actual nginx. My nginx confs work great what I miss is the actual ease of use of this software. But without geoip to protect my stuff and let only a country to access my websites and whitelist only some ip from the countrys i do not want to acess my stuff there is no way this is viable. Thanks for your consideration
Author
Owner

@nfacciolo commented on GitHub (May 5, 2023):

It's possible to install the module apt install libnginx-mod-http-geoip then create a custom file config nano /data/nginx/custom/http_top.conf Here you can add all your geo config then use created variable

<!-- gh-comment-id:1535984282 --> @nfacciolo commented on GitHub (May 5, 2023): It's possible to install the module `apt install libnginx-mod-http-geoip` then create a custom file config `nano /data/nginx/custom/http_top.conf` Here you can add all your geo config then use created variable
Author
Owner

@webysther commented on GitHub (May 8, 2023):

Maybe using this as reference: https://github.com/jlesage/docker-nginx-proxy-manager

<!-- gh-comment-id:1539144698 --> @webysther commented on GitHub (May 8, 2023): Maybe using this as reference: https://github.com/jlesage/docker-nginx-proxy-manager
Author
Owner

@lavinir commented on GitHub (May 9, 2023):

I've created a script that uses location data from db-ip.com to create country based access lists in nginx proxy manager.
They publish updated addresses monthly and you can just set up a cron schedule to run the script and update the access list that way.
More details here

<!-- gh-comment-id:1540026071 --> @lavinir commented on GitHub (May 9, 2023): I've created a script that uses location data from db-ip.com to create country based access lists in nginx proxy manager. They publish updated addresses monthly and you can just set up a cron schedule to run the script and update the access list that way. More details [here](https://github.com/lavinir/npm-geoaccesslists)
Author
Owner

@webysther commented on GitHub (May 15, 2023):

I decide to use like you @lavinir but in router direct with firewall and ip set, I just make download of geoip2 and use pandas to convert in CIDR ip list based on my needs. This solution have the advantage to remove the load from NPM, but will be great to have this. For someone that want to implement:

import pandas as pd

loc = pd.read_csv('data/GeoLite2-Country-Locations-en.csv')
ip4 = pd.read_csv('data/GeoLite2-Country-Blocks-IPv4.csv')

ip4loc = pd.merge(loc, ip4, on='geoname_id')

# countries you want to allow/block
country_list = ["BR","IT","NL","PT","CA"]

ip4loc = ip4loc[ip4loc['country_iso_code'].isin(country_list)]

path = 'data/allowed.zone.txt'
ip4loc.to_csv(path, columns = ["network"], header = False, index = False)

In my case I put this on a docker I make the update on Openwrt

<!-- gh-comment-id:1547713724 --> @webysther commented on GitHub (May 15, 2023): I decide to use like you @lavinir but in router direct with firewall and ip set, I just make download of geoip2 and use pandas to convert in CIDR ip list based on my needs. This solution have the advantage to remove the load from NPM, but will be great to have this. For someone that want to implement: ``` import pandas as pd loc = pd.read_csv('data/GeoLite2-Country-Locations-en.csv') ip4 = pd.read_csv('data/GeoLite2-Country-Blocks-IPv4.csv') ip4loc = pd.merge(loc, ip4, on='geoname_id') # countries you want to allow/block country_list = ["BR","IT","NL","PT","CA"] ip4loc = ip4loc[ip4loc['country_iso_code'].isin(country_list)] path = 'data/allowed.zone.txt' ip4loc.to_csv(path, columns = ["network"], header = False, index = False) ``` In my case I put this on a docker I make the update on [Openwrt](https://openwrt.org/docs/guide-user/firewall/fw3_configurations/fw3_config_ipset)
Author
Owner

@lavinir commented on GitHub (May 17, 2023):

@webysther . Cool.
For me, I have use cases where I need the filter on a per rule basis so I can't block everything at the router level. But if you want to block all traffic from certain locations to your home that's a great solution 👍

<!-- gh-comment-id:1551176657 --> @lavinir commented on GitHub (May 17, 2023): @webysther . Cool. For me, I have use cases where I need the filter on a per rule basis so I can't block everything at the router level. But if you want to block all traffic from certain locations to your home that's a great solution 👍
Author
Owner

@webysther commented on GitHub (May 21, 2023):

Yes my solution dont work per rule or domain.

<!-- gh-comment-id:1556290455 --> @webysther commented on GitHub (May 21, 2023): Yes my solution dont work per rule or domain.
Author
Owner

@GamerClassN7 commented on GitHub (Sep 14, 2023):

Hello,
Any news regarding implementation of geo module ?

Thanks for info

<!-- gh-comment-id:1719223099 --> @GamerClassN7 commented on GitHub (Sep 14, 2023): Hello, Any news regarding implementation of geo module ? Thanks for info
Author
Owner

@lavinir commented on GitHub (Sep 14, 2023):

Hi,

Unfortunately no, I haven't had the time to get back to this project yet..

<!-- gh-comment-id:1720251045 --> @lavinir commented on GitHub (Sep 14, 2023): Hi, Unfortunately no, I haven't had the time to get back to this project yet..
Author
Owner

@nfacciolo commented on GitHub (Sep 15, 2023):

If you install it directly on your server just install the dep : apt install libnginx-mod-http-geoip
If you use docker, create a dockerfile and RUN apt install libnginx-mod-http-geoip

<!-- gh-comment-id:1720715568 --> @nfacciolo commented on GitHub (Sep 15, 2023): If you install it directly on your server just install the dep : apt install libnginx-mod-http-geoip If you use docker, create a dockerfile and RUN apt install libnginx-mod-http-geoip
Author
Owner

@corvy commented on GitHub (Sep 15, 2023):

We should just fork and add it...

On Fri, 15 Sept 2023, 07:53 facciolo, @.***> wrote:

If you install it directly on your server just install the dep : apt
install libnginx-mod-http-geoip
If you use docker, create a dockerfile and RUN apt install
libnginx-mod-http-geoip


Reply to this email directly, view it on GitHub
https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1720715568,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AABBYNEZ53EUH5PBZGKMUFLX2PUONANCNFSM4GOX4ASA
.
You are receiving this because you commented.Message ID:
@.***>

<!-- gh-comment-id:1720828798 --> @corvy commented on GitHub (Sep 15, 2023): We should just fork and add it... On Fri, 15 Sept 2023, 07:53 facciolo, ***@***.***> wrote: > If you install it directly on your server just install the dep : apt > install libnginx-mod-http-geoip > If you use docker, create a dockerfile and RUN apt install > libnginx-mod-http-geoip > > — > Reply to this email directly, view it on GitHub > <https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1720715568>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AABBYNEZ53EUH5PBZGKMUFLX2PUONANCNFSM4GOX4ASA> > . > You are receiving this because you commented.Message ID: > ***@***.***> >
Author
Owner

@webysther commented on GitHub (Sep 15, 2023):

I don't think is a good ideia, the new version is coming and in some time in future, maybe add to the new version or make this new version flexible to support this kind of feature like mod of lsio

<!-- gh-comment-id:1720888686 --> @webysther commented on GitHub (Sep 15, 2023): I don't think is a good ideia, the new version is coming and in some time in future, maybe add to the new version or make this new version flexible to support this kind of feature like [mod of lsio](https://mods.linuxserver.io/)
Author
Owner

@GamerClassN7 commented on GitHub (Sep 20, 2023):

I don't think is a good ideia, the new version is coming and in some time in future, maybe add to the new version or make this new version flexible to support this kind of feature like mod of lsio

What is this mod site ?

<!-- gh-comment-id:1727255984 --> @GamerClassN7 commented on GitHub (Sep 20, 2023): > I don't think is a good ideia, the new version is coming and in some time in future, maybe add to the new version or make this new version flexible to support this kind of feature like [mod of lsio](https://mods.linuxserver.io/) What is this mod site ?
Author
Owner

@webysther commented on GitHub (Sep 21, 2023):

I don't think is a good ideia, the new version is coming and in some time in future, maybe add to the new version or make this new version flexible to support this kind of feature like mod of lsio

What is this mod site ?

https://mods.linuxserver.io/?mod=create

<!-- gh-comment-id:1729083698 --> @webysther commented on GitHub (Sep 21, 2023): > > I don't think is a good ideia, the new version is coming and in some time in future, maybe add to the new version or make this new version flexible to support this kind of feature like [mod of lsio](https://mods.linuxserver.io/) > > What is this mod site ? https://mods.linuxserver.io/?mod=create
Author
Owner

@wpresident commented on GitHub (Sep 22, 2023):

Can someone make complete instruction how to add geoip2 module in NPM docker?

<!-- gh-comment-id:1731154003 --> @wpresident commented on GitHub (Sep 22, 2023): Can someone make complete instruction how to add geoip2 module in NPM docker?
Author
Owner

@gzxiexl commented on GitHub (Oct 11, 2023):

I'm waiting too

<!-- gh-comment-id:1757537818 --> @gzxiexl commented on GitHub (Oct 11, 2023): I'm waiting too
Author
Owner

@bohemtucsok commented on GitHub (Oct 19, 2023):

I'm waiting too

<!-- gh-comment-id:1770401886 --> @bohemtucsok commented on GitHub (Oct 19, 2023): I'm waiting too
Author
Owner

@ThatCoffeeGuy commented on GitHub (Nov 10, 2023):

Yeah, same. Considering switching back to baremetal nginx only because of this. :(

❯ Starting nginx ...
nginx: [emerg] unknown directive "geoip_country" in /data/nginx/custom/http_top.conf:1

Is there an easy way to migrate from NPM docker to baremetal nginx? (fedora/ubuntu)

<!-- gh-comment-id:1805834901 --> @ThatCoffeeGuy commented on GitHub (Nov 10, 2023): Yeah, same. Considering switching back to baremetal nginx only because of this. :( ``` ❯ Starting nginx ... nginx: [emerg] unknown directive "geoip_country" in /data/nginx/custom/http_top.conf:1 ``` Is there an easy way to migrate from NPM docker to baremetal nginx? (fedora/ubuntu)
Author
Owner

@mixpc commented on GitHub (Feb 23, 2024):

+1 for the implementation of geoblock in nginx-proxy-manager

<!-- gh-comment-id:1961402479 --> @mixpc commented on GitHub (Feb 23, 2024): +1 for the implementation of geoblock in nginx-proxy-manager
Author
Owner

@nbently commented on GitHub (Feb 29, 2024):

Edited 6/7/24 to be more concise & easy to read.

The PR above adds support for this geoip2 module: https://github.com/leev/ngx_http_geoip2_module.

The nginx_http_geoip2 module has been added to the base nginx configuration and can now be configured in Nginx Proxy Manager with the latest images. I'm not keen on providing a ton of support for this, but here's how I have my config set up.

You need the GeoLite2-City database from MaxMind. You'll need to create an account to download it. Keep in mind that this database is regularly updated and can become outdated quickly. It is outside the scope of this comment, but you may want to consider automating the download of the database into your configuration on a regular basis.

I have three custom files and the GeoLite2-City database mounted into the NPM container. I'm using bind mounts and have these files stored on my host machine in my configuration directory for NPM.

  1. GeoLite2-City.mmdb, MaxMind
  2. enable_ngx_http_geoip2_module.conf
  3. http_top.conf, NPM docs
  4. server_proxy.conf, NPM docs

Configuration

GeoLite2-City.mmdb

This is the IP location database from MaxMind. This is how IPs are matched with locations.

Mount the IP database into the container here: /data/geoip2db/GeoLite2-City.mmdb.

enable_ngx_http_geoip2_module.conf

The module is now included in NPM, but we need to enable it. This file enables the module in nginx's configuration.

Mount this file into the container here: /etc/nginx/modules/enable_ngx_http_geoip2_module.conf

File contents:

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;

http_top.conf

This file tells the module where the GeoLite2-City database is and configures an additional log format that includes the IP location data in each log line.

Mount this file into the container here: /data/nginx/custom/http_top.conf.

File contents:

geoip2 /data/geoip2db/GeoLite2-City.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
$geoip2_data_city_name city names en;
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

server_proxy.conf

This file tells NPM to add the logging configuration you created above to each proxy host.

Mount this file into the container here: /data/nginx/custom/server_proxy.conf.

File contents:

access_log /data/logs/geoip.log geoip;

Feel free to tweak as it meets your needs, but this should get you up and running. This issue & #3334 should be able to be closed now.

Big thanks to @jc21 for getting the module merged so quickly.

<!-- gh-comment-id:1971318240 --> @nbently commented on GitHub (Feb 29, 2024): **Edited 6/7/24 to be more concise & easy to read.** The PR above adds support for this geoip2 module: https://github.com/leev/ngx_http_geoip2_module. The nginx_http_geoip2 module has been added to the base nginx configuration and can now be configured in Nginx Proxy Manager with the latest images. I'm not keen on providing a ton of support for this, but here's how I have my config set up. You need the GeoLite2-City database from [MaxMind](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data). You'll need to create an account to download it. Keep in mind that this database is regularly updated and can become outdated quickly. It is outside the scope of this comment, but you may want to consider automating the download of the database into your configuration on a regular basis. I have three [custom files](https://nginxproxymanager.com/advanced-config/#custom-nginx-configurations) and the GeoLite2-City database mounted into the NPM container. I'm using [bind mounts](https://docs.docker.com/storage/bind-mounts/) and have these files stored on my host machine in my configuration directory for NPM. 1. GeoLite2-City.mmdb, [MaxMind](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data) 2. enable_ngx_http_geoip2_module.conf 3. http_top.conf, [NPM docs](https://nginxproxymanager.com/advanced-config/#custom-nginx-configurations) 4. server_proxy.conf, [NPM docs](https://nginxproxymanager.com/advanced-config/#custom-nginx-configurations) ### Configuration #### GeoLite2-City.mmdb This is the IP location database from MaxMind. This is how IPs are matched with locations. Mount the IP database into the container here: `/data/geoip2db/GeoLite2-City.mmdb`. #### enable_ngx_http_geoip2_module.conf The module is now included in NPM, but we need to enable it. This file enables the module in nginx's configuration. Mount this file into the container here: `/etc/nginx/modules/enable_ngx_http_geoip2_module.conf` File contents: ``` load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; ``` #### http_top.conf This file tells the module where the GeoLite2-City database is and configures an additional log format that includes the IP location data in each log line. Mount this file into the container here: `/data/nginx/custom/http_top.conf`. File contents: ``` geoip2 /data/geoip2db/GeoLite2-City.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; $geoip2_data_city_name city names en; } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; ``` #### server_proxy.conf This file tells NPM to add the logging configuration you created above to each proxy host. Mount this file into the container here: `/data/nginx/custom/server_proxy.conf`. File contents: ``` access_log /data/logs/geoip.log geoip; ``` Feel free to tweak as it meets your needs, but this should get you up and running. This issue & #3334 should be able to be closed now. Big thanks to @jc21 for getting the module merged so quickly.
Author
Owner

@GamerClassN7 commented on GitHub (Apr 30, 2024):

The PR above adds support for this geoip2 module: https://github.com/leev/ngx_http_geoip2_module.

The nginx_http_geoip2 module has been added to the base nginx configuration and can now be configured in Nginx Proxy Manager with the latest images. I'm not keen on providing a ton of support for this, but here's how I have my config set up.

I've got the GeoLite2-City database from MaxMind mounted in the container at /data/geoip2db/GeoLite2-City.mmdb.

I've got a conf file mounted in the container at /etc/nginx/modules/enable_ngx_http_geoip2_module.conf to enable the module.

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;

I've got a conf file mounted in the container at /data/nginx/custom/http_top.conf to configure the module, tell it where the GeoLite2 db is located, and configure a log format.

geoip2 /data/geoip2db/GeoLite2-City.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
$geoip2_data_city_name city names en;
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

Finally, I've got a conf file mounted in the container at /data/nginx/custom/server_proxy.conf to instruct NPM to add a logging configuration to each proxy host.

access_log /data/logs/geoip.log geoip;

Feel free to tweak as it meets your needs, but this should get you up and running. This issue & #3334 should be able to be closed now.

Big thanks to @jc21 for getting the module merged so quickly.

Hello,
would be possible to add more detail step by step tutorial and put it to documentation maybe ?
I was not able to get it working in latest version of NPM :(

Thank in advance!

<!-- gh-comment-id:2084928620 --> @GamerClassN7 commented on GitHub (Apr 30, 2024): > The PR above adds support for this geoip2 module: https://github.com/leev/ngx_http_geoip2_module. > > The nginx_http_geoip2 module has been added to the base nginx configuration and can now be configured in Nginx Proxy Manager with the latest images. I'm not keen on providing a ton of support for this, but here's how I have my config set up. > > I've got the GeoLite2-City database from MaxMind mounted in the container at `/data/geoip2db/GeoLite2-City.mmdb`. > > I've got a conf file mounted in the container at `/etc/nginx/modules/enable_ngx_http_geoip2_module.conf` to enable the module. > > ``` > load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; > ``` > > I've got a conf file mounted in the container at `/data/nginx/custom/http_top.conf` to configure the module, tell it where the GeoLite2 db is located, and configure a log format. > > ``` > geoip2 /data/geoip2db/GeoLite2-City.mmdb { > auto_reload 5m; > $geoip2_data_country_iso_code country iso_code; > $geoip2_data_city_name city names en; > } > > log_format geoip '$remote_addr - $remote_user [$time_local]' > '"$request" $status $body_bytes_sent' > '"$http_referer" $host "$http_user_agent"' > '"$request_time" "$upstream_connect_time"' > '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; > ``` > > Finally, I've got a conf file mounted in the container at `/data/nginx/custom/server_proxy.conf` to instruct NPM to add a logging configuration to each proxy host. > > ``` > access_log /data/logs/geoip.log geoip; > ``` > > Feel free to tweak as it meets your needs, but this should get you up and running. This issue & #3334 should be able to be closed now. > > Big thanks to @jc21 for getting the module merged so quickly. Hello, would be possible to add more detail step by step tutorial and put it to documentation maybe ? I was not able to get it working in latest version of NPM :( Thank in advance!
Author
Owner

@coltography commented on GitHub (May 23, 2024):

@GamerClassN7 did you ever get this figured out? Everywhere I look is not very noob friendly explanations of how to get this set up properly.

<!-- gh-comment-id:2127458924 --> @coltography commented on GitHub (May 23, 2024): @GamerClassN7 did you ever get this figured out? Everywhere I look is not very noob friendly explanations of how to get this set up properly.
Author
Owner

@sbe-arg commented on GitHub (May 24, 2024):

Have a look at bunkerweb. Has geoblock included and other waf rules.

<!-- gh-comment-id:2128519385 --> @sbe-arg commented on GitHub (May 24, 2024): Have a look at bunkerweb. Has geoblock included and other waf rules.
Author
Owner

@coltography commented on GitHub (May 24, 2024):

Have a look at bunkerweb. Has geoblock included and other waf rules.

Thank you very much. Looks pretty neat, I'm wondering if it works with crowdsec. Will look into it.

<!-- gh-comment-id:2128591659 --> @coltography commented on GitHub (May 24, 2024): > Have a look at bunkerweb. Has geoblock included and other waf rules. Thank you very much. Looks pretty neat, I'm wondering if it works with crowdsec. Will look into it.
Author
Owner

@maboxx commented on GitHub (May 24, 2024):

What is bunkerweb? Maybe you have a link? Unfortunately I can't figure it out how it works and need more detailed instructions for dummies :-|

<!-- gh-comment-id:2128674001 --> @maboxx commented on GitHub (May 24, 2024): What is bunkerweb? Maybe you have a link? Unfortunately I can't figure it out how it works and need more detailed instructions for dummies :-|
Author
Owner

@phyte22 commented on GitHub (May 24, 2024):

I somehow managed it with NginxProxyManager. I can try to write a little noob tutorial here at the weekend, as I am one myself ^^

<!-- gh-comment-id:2128944174 --> @phyte22 commented on GitHub (May 24, 2024): I somehow managed it with NginxProxyManager. I can try to write a little noob tutorial here at the weekend, as I am one myself ^^
Author
Owner

@maboxx commented on GitHub (May 24, 2024):

Wow that would be really great and I would be so grateful...... I have been waiting for this function in NPM for a long time and now I have no idea what to do :-(

<!-- gh-comment-id:2129013235 --> @maboxx commented on GitHub (May 24, 2024): Wow that would be really great and I would be so grateful...... I have been waiting for this function in NPM for a long time and now I have no idea what to do :-(
Author
Owner

@phyte22 commented on GitHub (May 24, 2024):

I definitely wanted to whitelist countries, so I downloaded the country DB from https://dev.maxmind.com/geoip/geolite2-free-geolocation-data and put it in my Nginx folder.
My Folder looks like this:
image

you have to create 3 files (as described above)
http_top.conf (config)
enable_ngx_http_geoip2_module.conf (enables the geoip module)
server_proxy.conf (for logging)

my http_top.conf looks like this:
image
in this example Netherlands is accepted. just add your whitelistes countries here

try to access your new log (/data/logs/geoip.log) and look if the country db works when you access your urls (-> look at the last two values of the log line)

if this looks correct then just go to your ngx-gui and set this advanced config to make it work on your desired proxy
image

hope this helps in a way

<!-- gh-comment-id:2130372959 --> @phyte22 commented on GitHub (May 24, 2024): I definitely wanted to whitelist countries, so I downloaded the country DB from https://dev.maxmind.com/geoip/geolite2-free-geolocation-data and put it in my Nginx folder. My Folder looks like this: ![image](https://github.com/NginxProxyManager/nginx-proxy-manager/assets/18696598/d7654c68-b2e6-476d-aac9-7701ba3853f9) you have to create 3 files (as described above) `http_top.conf` (config) `enable_ngx_http_geoip2_module.conf` (enables the geoip module) `server_proxy.conf` (for logging) my `http_top.conf` looks like this: ![image](https://github.com/NginxProxyManager/nginx-proxy-manager/assets/18696598/c09d9229-57cc-4bce-aab5-af835f9f891c) in this example Netherlands is accepted. just add your whitelistes countries here try to access your new log (`/data/logs/geoip.log`) and look if the country db works when you access your urls (-> look at the last two values of the log line) if this looks correct then just go to your ngx-gui and set this advanced config to make it work on your desired proxy ![image](https://github.com/NginxProxyManager/nginx-proxy-manager/assets/18696598/926f0363-08a3-4fc1-a7ea-bdff92550809) hope this helps in a way
Author
Owner

@maboxx commented on GitHub (May 28, 2024):

@phyte22
Thank you so much!
I will be testing this very soon. I have NPM in Docker. I think my data folder is already set up “perstistent”. I'll have to check that again.

What I understood.

  1. Create 3 confs with the corresponding content.
    What content must the other two .conf have?
    enable_ngx_http_geoip2_module.conf
    server_proxy.conf

  2. Download the GeoLite2 Database:
    /data/geiip2db/GeoLite2-Country.mmdb

<!-- gh-comment-id:2134594523 --> @maboxx commented on GitHub (May 28, 2024): @phyte22 Thank you so much! I will be testing this very soon. I have NPM in Docker. I think my data folder is already set up “perstistent”. I'll have to check that again. What I understood. 1. Create 3 confs with the corresponding content. What content must the other two .conf have? enable_ngx_http_geoip2_module.conf server_proxy.conf 2. Download the GeoLite2 Database: /data/geiip2db/GeoLite2-Country.mmdb
Author
Owner

@phyte22 commented on GitHub (May 28, 2024):

for 1.
look at the post from https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1971318240

There you can see the content

<!-- gh-comment-id:2134721416 --> @phyte22 commented on GitHub (May 28, 2024): for 1. look at the post from https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1971318240 There you can see the content
Author
Owner

@maboxx commented on GitHub (May 29, 2024):

Ok I have tested, unfortunately it does not work.

  1. At first I did it like you @phyte22
    This is what my structure looked like:
access/
custom_ssl/
database.sqlite
enable_ngx_http_geoip2_module.conf
geoip2db/
   GeoLite2-Country.mmdb
http_top.conf
keys.json
letsencrypt-acme-challenge/
logs/
nginx/
server_proxy.conf

Then I restarted the NPM docker container.
As soon as I configured the Advanced tab in NPM on a proxy host, the proxy host went offline.

if($allowed_country=no) {
    return 444;
}

I have also not access to the log in /logs/geoip.log. The log is not created.

  1. Then I did it exactly like in https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1971318240 from @nbently
    My structure is then like this and I mounted also the conf in /etc/nginx/modules/enable_ngx_http_geoip2_module.conf
access/
custom/
  http_top.conf
  server_proxy.conf
custom_ssl/
database.sqlite
geoip2db/
   GeoLite2-Country.mmdb
keys.json
letsencrypt-acme-challenge/
logs/
nginx/

The result was the same. Do you or anyone else have any ideas?

<!-- gh-comment-id:2136784510 --> @maboxx commented on GitHub (May 29, 2024): Ok I have tested, unfortunately it does not work. 1. At first I did it like you @phyte22 This is what my structure looked like: ``` access/ custom_ssl/ database.sqlite enable_ngx_http_geoip2_module.conf geoip2db/ GeoLite2-Country.mmdb http_top.conf keys.json letsencrypt-acme-challenge/ logs/ nginx/ server_proxy.conf ``` Then I restarted the NPM docker container. As soon as I configured the Advanced tab in NPM on a proxy host, the proxy host went offline. ``` if($allowed_country=no) { return 444; } ``` I have also not access to the log in /logs/geoip.log. The log is not created. 2. Then I did it exactly like in https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-1971318240 from @nbently My structure is then like this and I mounted also the conf in /etc/nginx/modules/enable_ngx_http_geoip2_module.conf ``` access/ custom/ http_top.conf server_proxy.conf custom_ssl/ database.sqlite geoip2db/ GeoLite2-Country.mmdb keys.json letsencrypt-acme-challenge/ logs/ nginx/ ``` The result was the same. Do you or anyone else have any ideas?
Author
Owner

@phyte22 commented on GitHub (May 29, 2024):

What does it look like in your created files?
Before you

if($allowed_country=no) {
    return 444;
}

you should first have a working log.
The file geoip.log is not created under any circumstances?
Then something fundamental does not seem to be working...

<!-- gh-comment-id:2137577654 --> @phyte22 commented on GitHub (May 29, 2024): What does it look like in your created files? Before you ``` if($allowed_country=no) { return 444; } ``` you should first have a working log. The file `geoip.log` is not created under any circumstances? Then something fundamental does not seem to be working...
Author
Owner

@maboxx commented on GitHub (May 30, 2024):

Here the content from the files and once again my current structure:

access/
custom/
  http_top.conf
  server_proxy.conf
custom_ssl/
database.sqlite
geoip2db/
   GeoLite2-Country.mmdb
keys.json
letsencrypt-acme-challenge/
logs/
nginx/

http_top.conf

geoip2 /data/geoip2db/GeoLite2-City.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
}

map $geoip2_data_country_iso_code $allowed_country {
   default: no;
   DE yes; # Germany
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

server_proxy.conf

access_log /data/logs/geoip.log geoip;

enable_ngx_http_geoip2_module.conf, mounted on /etc/nginx/modules/

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;

I also look to the usr/lib/nginx/mdules path if the .so file exists and it is there!
But at the end the geoip.log is not created.

<!-- gh-comment-id:2138825377 --> @maboxx commented on GitHub (May 30, 2024): Here the content from the files and once again my current structure: ``` access/ custom/ http_top.conf server_proxy.conf custom_ssl/ database.sqlite geoip2db/ GeoLite2-Country.mmdb keys.json letsencrypt-acme-challenge/ logs/ nginx/ ``` http_top.conf ``` geoip2 /data/geoip2db/GeoLite2-City.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } map $geoip2_data_country_iso_code $allowed_country { default: no; DE yes; # Germany } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; ``` server_proxy.conf ``` access_log /data/logs/geoip.log geoip; ``` enable_ngx_http_geoip2_module.conf, mounted on /etc/nginx/modules/ ``` load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; ``` I also look to the usr/lib/nginx/mdules path if the .so file exists and it is there! But at the end the geoip.log is not created.
Author
Owner

@phyte22 commented on GitHub (May 30, 2024):

geoip2 /data/geoip2db/GeoLite2-City.mmdb {

you referenced the City DB. But you downloaded, as i did, the Country DB :D

<!-- gh-comment-id:2140168285 --> @phyte22 commented on GitHub (May 30, 2024): > `geoip2 /data/geoip2db/GeoLite2-City.mmdb {` you referenced the City DB. But you downloaded, as i did, the Country DB :D
Author
Owner

@maboxx commented on GitHub (May 30, 2024):

You 're right :-) I changed it and restart the container but same result. The geoip.log still not created :-(
The configuration looks good I think but still not working.....

<!-- gh-comment-id:2140621559 --> @maboxx commented on GitHub (May 30, 2024): You 're right :-) I changed it and restart the container but same result. The geoip.log still not created :-( The configuration looks good I think but still not working.....
Author
Owner

@phyte22 commented on GitHub (May 30, 2024):

Hmm.. you can remove $geoip2_data_city_name out of the log.
Additionally this are all my releated mounts for the NPM Container:
/data/nginx/custom/server_proxy.conf
/data/nginx/custom/http_top.conf
/data/geoip2db/GeoLite2-Country.mmdb
/etc/nginx/modules/enable_ngx_http_geoip2_module.conf

maybe you are missing something here?
Are you running the latest version?

<!-- gh-comment-id:2140952352 --> @phyte22 commented on GitHub (May 30, 2024): Hmm.. you can remove `$geoip2_data_city_name` out of the log. Additionally this are all my releated mounts for the NPM Container: `/data/nginx/custom/server_proxy.conf` `/data/nginx/custom/http_top.conf` `/data/geoip2db/GeoLite2-Country.mmdb` `/etc/nginx/modules/enable_ngx_http_geoip2_module.conf` maybe you are missing something here? Are you running the latest version?
Author
Owner

@maboxx commented on GitHub (May 31, 2024):

I don't know what you mean with remove "$geoip2_data_city_name" out of the log? Can you explain again please?
It looks the same for me as it does for you, I have the same mounts as you.
The version is Version 2.11.2

See from inside the container:

http_top.conf

 _   _       _            ____                      __  __                                   
| \ | | __ _(_)_ __ __  _|  _ \ _ __ _____  ___   _|  \/  | __ _ _ __   __ _  __ _  ___ _ __ 
|  \| |/ _` | | '_ \\ \/ / |_) | '__/ _ \ \/ / | | | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
| |\  | (_| | | | | |>  <|  __/| | | (_) >  <| |_| | |  | | (_| | | | | (_| | (_| |  __/ |   
|_| \_|\__, |_|_| |_/_/\_\_|   |_|  \___/_/\_\\__, |_|  |_|\__,_|_| |_|\__,_|\__, |\___|_|   
       |___/                                  |___/                          |___/           
Version 2.11.2 (12d77e3) 2024-05-22 22:49:17 UTC, OpenResty 1.21.4.3, debian 12 (bookworm), Certbot certbot 2.10.0
Base: debian:bookworm-slim, linux/amd64
Certbot: nginxproxymanager/nginx-full:latest, linux/amd64
Node: nginxproxymanager/nginx-full:certbot, linux/amd64


[root@docker-a256c6b611ca:/app]# cat /data/custom/http_top.conf 
geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
}

map $geoip2_data_country_iso_code $allowed_country {
   default: no;
   DE yes; # Germany
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

server_proxy.conf

[root@docker-a256c6b611ca:/app]# cat /data/custom/server_proxy.conf 
access_log /data/logs/geoip.log geoip;

GeoLite2-Country.mmdb

[root@docker-a256c6b611ca:/app]# ls /data/geoip2db/
GeoLite2-Country.mmdb

enable_ngx_http_geoip2_module.conf

[root@docker-a256c6b611ca:/app]# cat /etc/nginx/modules/enable_ngx_http_geoip2_module.conf 
load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;

The modules also exists:

[root@docker-a256c6b611ca:/app]# ls /usr/lib/nginx/modules/
ngx_http_geoip2_module.so
ngx_stream_geoip2_module.so

Is it perhaps not enough just to restart the container? Do I perhaps have to delete it completely first? I don't think so.

<!-- gh-comment-id:2141327197 --> @maboxx commented on GitHub (May 31, 2024): I don't know what you mean with remove "$geoip2_data_city_name" out of the log? Can you explain again please? It looks the same for me as it does for you, I have the same mounts as you. The version is Version 2.11.2 See from inside the container: http_top.conf ``` _ _ _ ____ __ __ | \ | | __ _(_)_ __ __ _| _ \ _ __ _____ ___ _| \/ | __ _ _ __ __ _ __ _ ___ _ __ | \| |/ _` | | '_ \\ \/ / |_) | '__/ _ \ \/ / | | | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__| | |\ | (_| | | | | |> <| __/| | | (_) > <| |_| | | | | (_| | | | | (_| | (_| | __/ | |_| \_|\__, |_|_| |_/_/\_\_| |_| \___/_/\_\\__, |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |___/ |___/ |___/ Version 2.11.2 (12d77e3) 2024-05-22 22:49:17 UTC, OpenResty 1.21.4.3, debian 12 (bookworm), Certbot certbot 2.10.0 Base: debian:bookworm-slim, linux/amd64 Certbot: nginxproxymanager/nginx-full:latest, linux/amd64 Node: nginxproxymanager/nginx-full:certbot, linux/amd64 [root@docker-a256c6b611ca:/app]# cat /data/custom/http_top.conf geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } map $geoip2_data_country_iso_code $allowed_country { default: no; DE yes; # Germany } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; ``` server_proxy.conf ``` [root@docker-a256c6b611ca:/app]# cat /data/custom/server_proxy.conf access_log /data/logs/geoip.log geoip; ``` GeoLite2-Country.mmdb ``` [root@docker-a256c6b611ca:/app]# ls /data/geoip2db/ GeoLite2-Country.mmdb ``` enable_ngx_http_geoip2_module.conf ``` [root@docker-a256c6b611ca:/app]# cat /etc/nginx/modules/enable_ngx_http_geoip2_module.conf load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; ``` The modules also exists: ``` [root@docker-a256c6b611ca:/app]# ls /usr/lib/nginx/modules/ ngx_http_geoip2_module.so ngx_stream_geoip2_module.so ``` Is it perhaps not enough just to restart the container? Do I perhaps have to delete it completely first? I don't think so.
Author
Owner

@phyte22 commented on GitHub (Jun 1, 2024):

in my log_format I don't have “$geoip2_data_city_name” because we don't get the variable from the database.

apart from that, it's really weird... i didn't do more, if i remember correctly. Do you have any other NPM logs that might indicate that the geoip module could not be loaded or similar?

<!-- gh-comment-id:2143198837 --> @phyte22 commented on GitHub (Jun 1, 2024): in my log_format I don't have “$geoip2_data_city_name” because we don't get the variable from the database. apart from that, it's really weird... i didn't do more, if i remember correctly. Do you have any other NPM logs that might indicate that the geoip module could not be loaded or similar?
Author
Owner

@maboxx commented on GitHub (Jun 1, 2024):

I have now adjusted the log format, but it does not change anything.

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

This is the log when I restart the NPM docker container:

[6/1/2024] [4:22:19 PM] [Global   ] › ℹ  info      PID 166 received SIGTERM
[6/1/2024] [4:22:19 PM] [Global   ] › ℹ  info      Stopping.
❯ Configuring npm user ...
0
usermod: no changes
❯ Configuring npm group ...
❯ Checking paths ...
❯ Setting ownership ...
❯ Dynamic resolvers ...
❯ IPv6 ...
Enabling IPV6 in hosts in: /etc/nginx/conf.d
- /etc/nginx/conf.d/include/force-ssl.conf
- /etc/nginx/conf.d/include/proxy.conf
- /etc/nginx/conf.d/include/letsencrypt-acme-challenge.conf
- /etc/nginx/conf.d/include/block-exploits.conf
- /etc/nginx/conf.d/include/assets.conf
- /etc/nginx/conf.d/include/ssl-ciphers.conf
- /etc/nginx/conf.d/include/ip_ranges.conf
- /etc/nginx/conf.d/include/resolvers.conf
- /etc/nginx/conf.d/production.conf
- /etc/nginx/conf.d/default.conf
Enabling IPV6 in hosts in: /data/nginx
- /data/nginx/proxy_host/3.conf
- /data/nginx/proxy_host/6.conf
- /data/nginx/proxy_host/7.conf
- /data/nginx/proxy_host/18.conf
- /data/nginx/proxy_host/15.conf
- /data/nginx/proxy_host/2.conf
- /data/nginx/proxy_host/4.conf
- /data/nginx/proxy_host/24.conf
- /data/nginx/proxy_host/28.conf
- /data/nginx/proxy_host/29.conf
- /data/nginx/proxy_host/27.conf
- /data/nginx/proxy_host/5.conf
- /data/nginx/stream/1.conf
❯ Docker secrets ...
-------------------------------------
 _   _ ____  __  __
| \ | |  _ \|  \/  |
|  \| | |_) | |\/| |
| |\  |  __/| |  | |
|_| \_|_|   |_|  |_|
-------------------------------------
User:  npm PUID:0 ID:0 GROUP:0
Group: npm PGID:0 ID:0
-------------------------------------
❯ Starting backend ...
❯ Starting nginx ...
[6/1/2024] [4:22:24 PM] [Global   ] › ℹ  info      Using Sqlite: /data/database.sqlite
[6/1/2024] [4:22:25 PM] [Migrate  ] › ℹ  info      Current database version: none
[6/1/2024] [4:22:25 PM] [Setup    ] › ℹ  info      Logrotate Timer initialized
[6/1/2024] [4:22:25 PM] [Global   ] › ⬤  debug     CMD: logrotate /etc/logrotate.d/nginx-proxy-manager
[6/1/2024] [4:22:25 PM] [Setup    ] › ℹ  info      Logrotate completed.
[6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ  info      Fetching IP Ranges from online services...
[6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ  info      Fetching https://ip-ranges.amazonaws.com/ip-ranges.json
[6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ  info      Fetching https://www.cloudflare.com/ips-v4
[6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ  info      Fetching https://www.cloudflare.com/ips-v6
[6/1/2024] [4:22:26 PM] [SSL      ] › ℹ  info      Let's Encrypt Renewal Timer initialized
[6/1/2024] [4:22:26 PM] [SSL      ] › ℹ  info      Renewing SSL certs expiring within 30 days ...
[6/1/2024] [4:22:26 PM] [IP Ranges] › ℹ  info      IP Ranges Renewal Timer initialized
[6/1/2024] [4:22:26 PM] [Global   ] › ℹ  info      Backend PID 166 listening on port 3000 ...
[6/1/2024] [4:22:26 PM] [SSL      ] › ℹ  info      Completed SSL cert renew process
      
<!-- gh-comment-id:2143505249 --> @maboxx commented on GitHub (Jun 1, 2024): I have now adjusted the log format, but it does not change anything. ``` log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; ``` This is the log when I restart the NPM docker container: ``` [6/1/2024] [4:22:19 PM] [Global ] › ℹ info PID 166 received SIGTERM [6/1/2024] [4:22:19 PM] [Global ] › ℹ info Stopping. ❯ Configuring npm user ... 0 usermod: no changes ❯ Configuring npm group ... ❯ Checking paths ... ❯ Setting ownership ... ❯ Dynamic resolvers ... ❯ IPv6 ... Enabling IPV6 in hosts in: /etc/nginx/conf.d - /etc/nginx/conf.d/include/force-ssl.conf - /etc/nginx/conf.d/include/proxy.conf - /etc/nginx/conf.d/include/letsencrypt-acme-challenge.conf - /etc/nginx/conf.d/include/block-exploits.conf - /etc/nginx/conf.d/include/assets.conf - /etc/nginx/conf.d/include/ssl-ciphers.conf - /etc/nginx/conf.d/include/ip_ranges.conf - /etc/nginx/conf.d/include/resolvers.conf - /etc/nginx/conf.d/production.conf - /etc/nginx/conf.d/default.conf Enabling IPV6 in hosts in: /data/nginx - /data/nginx/proxy_host/3.conf - /data/nginx/proxy_host/6.conf - /data/nginx/proxy_host/7.conf - /data/nginx/proxy_host/18.conf - /data/nginx/proxy_host/15.conf - /data/nginx/proxy_host/2.conf - /data/nginx/proxy_host/4.conf - /data/nginx/proxy_host/24.conf - /data/nginx/proxy_host/28.conf - /data/nginx/proxy_host/29.conf - /data/nginx/proxy_host/27.conf - /data/nginx/proxy_host/5.conf - /data/nginx/stream/1.conf ❯ Docker secrets ... ------------------------------------- _ _ ____ __ __ | \ | | _ \| \/ | | \| | |_) | |\/| | | |\ | __/| | | | |_| \_|_| |_| |_| ------------------------------------- User: npm PUID:0 ID:0 GROUP:0 Group: npm PGID:0 ID:0 ------------------------------------- ❯ Starting backend ... ❯ Starting nginx ... [6/1/2024] [4:22:24 PM] [Global ] › ℹ info Using Sqlite: /data/database.sqlite [6/1/2024] [4:22:25 PM] [Migrate ] › ℹ info Current database version: none [6/1/2024] [4:22:25 PM] [Setup ] › ℹ info Logrotate Timer initialized [6/1/2024] [4:22:25 PM] [Global ] › ⬤ debug CMD: logrotate /etc/logrotate.d/nginx-proxy-manager [6/1/2024] [4:22:25 PM] [Setup ] › ℹ info Logrotate completed. [6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ info Fetching IP Ranges from online services... [6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ info Fetching https://ip-ranges.amazonaws.com/ip-ranges.json [6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ info Fetching https://www.cloudflare.com/ips-v4 [6/1/2024] [4:22:25 PM] [IP Ranges] › ℹ info Fetching https://www.cloudflare.com/ips-v6 [6/1/2024] [4:22:26 PM] [SSL ] › ℹ info Let's Encrypt Renewal Timer initialized [6/1/2024] [4:22:26 PM] [SSL ] › ℹ info Renewing SSL certs expiring within 30 days ... [6/1/2024] [4:22:26 PM] [IP Ranges] › ℹ info IP Ranges Renewal Timer initialized [6/1/2024] [4:22:26 PM] [Global ] › ℹ info Backend PID 166 listening on port 3000 ... [6/1/2024] [4:22:26 PM] [SSL ] › ℹ info Completed SSL cert renew process ```
Author
Owner

@cruunnerr commented on GitHub (Jun 4, 2024):

@maboxx
Hey there. Since you seem to be German, you might want to have a look at this site: https://decatec.de/home-server/nginx-besucher-mittels-geoip2-nach-laendern-blockieren-geoblocking/

This is pretty much the same as @phyte22 described. So maybe that helps you. Would be nice if you report your config if it works correctly.

Also think about not blocking your own LAN by adding something like:

geo $lan-ip {
default no;
192.168.1.0/24 yes; # your personal LAN
}

if ($lan-ip = yes) {
set $allowed_country yes;
}

if ($allowed_country = no) {
return 444;
}
<!-- gh-comment-id:2148398834 --> @cruunnerr commented on GitHub (Jun 4, 2024): @maboxx Hey there. Since you seem to be German, you might want to have a look at this site: https://decatec.de/home-server/nginx-besucher-mittels-geoip2-nach-laendern-blockieren-geoblocking/ This is pretty much the same as @phyte22 described. So maybe that helps you. Would be nice if you report your config if it works correctly. Also think about not blocking your own LAN by adding something like: ``` geo $lan-ip { default no; 192.168.1.0/24 yes; # your personal LAN } if ($lan-ip = yes) { set $allowed_country yes; } if ($allowed_country = no) { return 444; } ```
Author
Owner

@maboxx commented on GitHub (Jun 7, 2024):

Thank you for the link but
But I just don't think I understand it completely, I'm so sorry. The link only concerns me from the point "nginx-Konfiguration für GeoIP2" Because the geoip module is already integrated in NPM, isn't it?

<!-- gh-comment-id:2154064265 --> @maboxx commented on GitHub (Jun 7, 2024): Thank you for the link but But I just don't think I understand it completely, I'm so sorry. The link only concerns me from the point "nginx-Konfiguration für GeoIP2" Because the geoip module is already integrated in NPM, isn't it?
Author
Owner

@nbently commented on GitHub (Jun 7, 2024):

@maboxx you might want to check to make sure your log_format configuration only includes variables present in the file you downloaded. I haven't tested this on the Country db, but theoretically it should still work, and it does seem like others have gotten it to work. FWIW the City db includes everything in the Country db but not the other way around. https://dev.maxmind.com/geoip/docs/databases/city-and-country#locations-files

Make sure your bind mounts are correct as well (e.g. the file on the host system is where you say it is).

I would suggest trying with my exact configuration first to see if that works and then tweaking it from there.

<!-- gh-comment-id:2155490650 --> @nbently commented on GitHub (Jun 7, 2024): @maboxx you might want to check to make sure your log_format configuration only includes variables present in the file you downloaded. I haven't tested this on the Country db, but theoretically it should still work, and it does seem like others have gotten it to work. FWIW the City db includes everything in the Country db but not the other way around. https://dev.maxmind.com/geoip/docs/databases/city-and-country#locations-files Make sure your bind mounts are correct as well (e.g. the file on the host system is where you say it is). I would suggest trying with my exact configuration first to see if that works and then tweaking it from there.
Author
Owner

@maboxx commented on GitHub (Jun 8, 2024):

@nbently
I do it now exactly like you:

[root@docker-a256c6b611ca:/app]# ls -ltr /data/
total 516
-rw-r--r-- 1 root root   2190 Feb  9 20:30 keys.json
drwxr-xr-x 1 root root     22 Feb 15 10:04 letsencrypt-acme-challenge
drwxr-xr-x 1 root root    136 Feb 15 10:04 nginx
drwxr-xr-x 1 root root      0 Feb 18 22:31 access
drwxr-xr-x 1 root root    120 Feb 24 15:23 custom_ssl
-rw-r--r-- 1 root root 524288 Jun  2 07:19 database.sqlite
drwxr-xr-x 1 root root  12584 Jun  2 07:19 logs
drwxr-x--- 1 root root     60 Jun  8 07:28 custom
drwxr-x--- 1 root root     78 Jun  8 07:33 geoip2db

[root@docker-a256c6b611ca:/app]# ls -ltr /data/custom/
total 8
-rw-r----- 1 root root  39 May 29 07:26 server_proxy.conf
-rw-r----- 1 root root 437 Jun  8 07:23 http_top.conf

[root@docker-a256c6b611ca:/app]# ls -ltr /data/geoip2db/
total 55284
-rw-r----- 1 root root 50097859 Jun  7 15:49 GeoLite2-City.mmdb

[root@docker-a256c6b611ca:/app]# cat /data/custom/server_proxy.conf 
access_log /data/logs/geoip.log geoip;

[root@docker-a256c6b611ca:/app]# cat /data/custom/http_top.conf    
geoip2 /data/geoip2db/GeoLite2-City.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
$geoip2_data_city_name city names en;
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

[root@docker-a256c6b611ca:/app]# ls -ltr /data/geoip2db/           
total 55284
-rw-r----- 1 root root 50097859 Jun  7 15:49 GeoLite2-City.mmdb

[root@docker-a256c6b611ca:/app]# cat /etc/nginx/modules/enable_ngx_http_geoip2_module.conf 
load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;

I have now started Docker. How can I now check whether the module is loaded or working?

<!-- gh-comment-id:2155858642 --> @maboxx commented on GitHub (Jun 8, 2024): @nbently I do it now exactly like you: ``` [root@docker-a256c6b611ca:/app]# ls -ltr /data/ total 516 -rw-r--r-- 1 root root 2190 Feb 9 20:30 keys.json drwxr-xr-x 1 root root 22 Feb 15 10:04 letsencrypt-acme-challenge drwxr-xr-x 1 root root 136 Feb 15 10:04 nginx drwxr-xr-x 1 root root 0 Feb 18 22:31 access drwxr-xr-x 1 root root 120 Feb 24 15:23 custom_ssl -rw-r--r-- 1 root root 524288 Jun 2 07:19 database.sqlite drwxr-xr-x 1 root root 12584 Jun 2 07:19 logs drwxr-x--- 1 root root 60 Jun 8 07:28 custom drwxr-x--- 1 root root 78 Jun 8 07:33 geoip2db [root@docker-a256c6b611ca:/app]# ls -ltr /data/custom/ total 8 -rw-r----- 1 root root 39 May 29 07:26 server_proxy.conf -rw-r----- 1 root root 437 Jun 8 07:23 http_top.conf [root@docker-a256c6b611ca:/app]# ls -ltr /data/geoip2db/ total 55284 -rw-r----- 1 root root 50097859 Jun 7 15:49 GeoLite2-City.mmdb [root@docker-a256c6b611ca:/app]# cat /data/custom/server_proxy.conf access_log /data/logs/geoip.log geoip; [root@docker-a256c6b611ca:/app]# cat /data/custom/http_top.conf geoip2 /data/geoip2db/GeoLite2-City.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; $geoip2_data_city_name city names en; } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; [root@docker-a256c6b611ca:/app]# ls -ltr /data/geoip2db/ total 55284 -rw-r----- 1 root root 50097859 Jun 7 15:49 GeoLite2-City.mmdb [root@docker-a256c6b611ca:/app]# cat /etc/nginx/modules/enable_ngx_http_geoip2_module.conf load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; ``` I have now started Docker. How can I now check whether the module is loaded or working?
Author
Owner

@nbently commented on GitHub (Jun 8, 2024):

@maboxx if you're in the container you should now see a new log in /data/logs called geoip.log. That file will contain all of the new log data with the location data in each line. Make sure you have at least one proxy host set up and configured as well (otherwise there won't be any logs).

<!-- gh-comment-id:2156080125 --> @nbently commented on GitHub (Jun 8, 2024): @maboxx if you're in the container you should now see a new log in /data/logs called geoip.log. That file will contain all of the new log data with the location data in each line. Make sure you have at least one proxy host set up and configured as well (otherwise there won't be any logs).
Author
Owner

@maboxx commented on GitHub (Jun 8, 2024):

@nbently

I am sad, there is no log :-(

[root@docker-a256c6b611ca:/data/logs]# ls -ltr geoip.log
ls: cannot access 'geoip.log': No such file or directory
[root@docker-a256c6b611ca:/data/logs]# 

I don't understand it. I do exactly what you do.

<!-- gh-comment-id:2156141778 --> @maboxx commented on GitHub (Jun 8, 2024): @nbently I am sad, there is no log :-( ``` [root@docker-a256c6b611ca:/data/logs]# ls -ltr geoip.log ls: cannot access 'geoip.log': No such file or directory [root@docker-a256c6b611ca:/data/logs]# ``` I don't understand it. I do exactly what you do.
Author
Owner

@cruunnerr commented on GitHub (Jun 10, 2024):

@maboxx

I don't have much time at the moment. Will try to make you a noob-friendly HowTo till the weekend.

Just notice: I have my NPM docker folder in my home directory.

Basically I installed GeoIP like here: https://dev.maxmind.com/geoip/updating-databases

sudo add-apt-repository ppa:maxmind/ppa
sudo apt update
sudo apt install geoipupdate

I changed the DatabaseDirectory in /etc/GeoIP.conf:
DatabaseDirectory /home/USER/NPM_DOCKER_FOLDER/GeoIP
Also you need to insert your account-details here.

First try to download database:
sudo geoipupdate
should create you the database files in the /home/USER/NPM_DOCKER_FOLDER/GeoIP

Then created a crontab for updating database.

sudo crontab -e
content:

# m h  dom mon dow   command
14 21 * * * geoipupdate

Then I created the files

NPM_DOCKER_FOLDER/modules/enable_ngx_http_geoip2_module.conf
NPM_DOCKER_FOLDER/data/nginx/custom/http_top.conf
NPM_DOCKER_FOLDER/data/nginx/custom/server_proxy.conf

My files look like this:

enable_ngx_http_geoip2_module.conf:
load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;

http_top.conf:

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
}

map $geoip2_data_country_iso_code $allowed_country {
    default no;
    10.0.0.0/8 yes;
    192.168.0.0/16 yes;
    DE yes;

}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_country_iso_code" "$allowed_country"';
           #'"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

server_proxy.conf:

if ($allowed_country = no) {
        return 444;
}
access_log /data/logs/geoip.log geoip;

Then I added the volume mounts to the docker-compose.yml:

version: "3"
services:
  app:
    image: jc21/nginx-proxy-manager:latest
    restart: always
    ports:
      - 80:80
      - 81:81
      - 443:443
    volumes:
      - ./config.json:/app/config/production.json
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
      - ./modules:/etc/nginx/modules
      - ./GeoIP:/data/geoip2db
    depends_on:
      - db
    environment:
    # if you want pretty colors in your docker logs:
    - FORCE_COLOR=1
  db:
    image: mariadb:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "_PRIVATE_"
      MYSQL_DATABASE: "_PRIVATE_"
      MYSQL_USER: "_PRIVATE_"
      MYSQL_PASSWORD: "_PRIVATE_"
    volumes:
      - ./data/mysql:/var/lib/mysql

start the container:

sudo docker-compose up -d

Notice that I added the

if ($allowed_country = no) {
        return 444;
}

part inside the server_proxy.conf, since I couldn't get it worked with adding these lines in the webUI. But it worked pretty well. I tested accessing my proxy hosts via VPN from different countries, and only Germany got a response. :)

<!-- gh-comment-id:2159164330 --> @cruunnerr commented on GitHub (Jun 10, 2024): @maboxx I don't have much time at the moment. Will try to make you a noob-friendly HowTo till the weekend. Just notice: I have my NPM docker folder in my home directory. Basically I installed GeoIP like here: https://dev.maxmind.com/geoip/updating-databases `sudo add-apt-repository ppa:maxmind/ppa` `sudo apt update` `sudo apt install geoipupdate` I changed the DatabaseDirectory in /etc/GeoIP.conf: `DatabaseDirectory /home/USER/NPM_DOCKER_FOLDER/GeoIP` **Also you need to insert your account-details here.** First try to download database: `sudo geoipupdate` should create you the database files in the /home/USER/NPM_DOCKER_FOLDER/GeoIP Then created a crontab for updating database. `sudo crontab -e` content: ``` # m h dom mon dow command 14 21 * * * geoipupdate ``` Then I created the files _NPM_DOCKER_FOLDER_/modules/enable_ngx_http_geoip2_module.conf _NPM_DOCKER_FOLDER_/data/nginx/custom/http_top.conf _NPM_DOCKER_FOLDER_/data/nginx/custom/server_proxy.conf My files look like this: enable_ngx_http_geoip2_module.conf: ```load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;``` http_top.conf: ``` geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } map $geoip2_data_country_iso_code $allowed_country { default no; 10.0.0.0/8 yes; 192.168.0.0/16 yes; DE yes; } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_country_iso_code" "$allowed_country"'; #'"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; ``` server_proxy.conf: ``` if ($allowed_country = no) { return 444; } access_log /data/logs/geoip.log geoip; ``` Then I added the volume mounts to the docker-compose.yml: ``` version: "3" services: app: image: jc21/nginx-proxy-manager:latest restart: always ports: - 80:80 - 81:81 - 443:443 volumes: - ./config.json:/app/config/production.json - ./data:/data - ./letsencrypt:/etc/letsencrypt - ./modules:/etc/nginx/modules - ./GeoIP:/data/geoip2db depends_on: - db environment: # if you want pretty colors in your docker logs: - FORCE_COLOR=1 db: image: mariadb:latest restart: always environment: MYSQL_ROOT_PASSWORD: "_PRIVATE_" MYSQL_DATABASE: "_PRIVATE_" MYSQL_USER: "_PRIVATE_" MYSQL_PASSWORD: "_PRIVATE_" volumes: - ./data/mysql:/var/lib/mysql ``` start the container: `sudo docker-compose up -d` Notice that I added the ``` if ($allowed_country = no) { return 444; } ``` part inside the server_proxy.conf, since I couldn't get it worked with adding these lines in the webUI. But it worked pretty well. I tested accessing my proxy hosts via VPN from different countries, and only Germany got a response. :)
Author
Owner

@maboxx commented on GitHub (Jun 11, 2024):

Thank you very much @cruunnerr @nbently @phyte22 for your patience and effort, I will check again point by point as soon as I have time.

<!-- gh-comment-id:2161139207 --> @maboxx commented on GitHub (Jun 11, 2024): Thank you very much @cruunnerr @nbently @phyte22 for your patience and effort, I will check again point by point as soon as I have time.
Author
Owner

@cruunnerr commented on GitHub (Jun 11, 2024):

Thank you very much @cruunnerr @nbently @phyte22 for your patience and effort, I will check again point by point as soon as I have time.

You're very welcome. Please keep in mind, that GeoIP-Blocking is a nice thing to have, but doesn't free your server from getting attacked.
It is good for blocking bots and crawlers and surely prevents your proxy hosts from being inspected from several countries. But attackers often use bot nets and have several bots in different countries. So it kind of protects you from getting attacked from "everywhere".
But I would definitely recommend you to also install crowdsec (or at least fail2ban) on your bare NPM-Server. Since crowdsec detects basically even before the packets reaches your NPM-Docker instance and can effectively protect against many kinds of attacks on vulnerabilities or exploits. Just imagine NPM or your OS has a vulnerability which can be attacked even before packets reach your Hosts or your NPM Docker instance.
For example my crowdsec instance detected around 25 scenarios and blocked the IP's, just for today! For the hole June I have actually 473 blocked scenarios (85 of them from Germany, which even wouldn't have been blocked via GeoIP).

Just think about it ;)

<!-- gh-comment-id:2161420014 --> @cruunnerr commented on GitHub (Jun 11, 2024): > Thank you very much @cruunnerr @nbently @phyte22 for your patience and effort, I will check again point by point as soon as I have time. You're very welcome. Please keep in mind, that GeoIP-Blocking is a nice thing to have, but doesn't free your server from getting attacked. It is good for blocking bots and crawlers and surely prevents your proxy hosts from being inspected from several countries. But attackers often use bot nets and have several bots in different countries. So it kind of protects you from getting attacked from "everywhere". But I would definitely recommend you to also install crowdsec (or at least fail2ban) on your bare NPM-Server. Since crowdsec detects basically even before the packets reaches your NPM-Docker instance and can effectively protect against many kinds of attacks on vulnerabilities or exploits. Just imagine NPM or your OS has a vulnerability which can be attacked even before packets reach your Hosts or your NPM Docker instance. For example my crowdsec instance detected around 25 scenarios and blocked the IP's, just for today! For the hole June I have actually 473 blocked scenarios (85 of them from Germany, which even wouldn't have been blocked via GeoIP). Just think about it ;)
Author
Owner

@nbently commented on GitHub (Jun 11, 2024):

@maboxx can you show us where you have the bind mounts configured?

<!-- gh-comment-id:2161667019 --> @nbently commented on GitHub (Jun 11, 2024): @maboxx can you show us where you have the bind mounts configured?
Author
Owner

@maboxx commented on GitHub (Jun 12, 2024):

I probably won't have time to go through the whole thing again until the weekend.
@cruunnerr
Thank you very much for the tips.
My constellation is such that my NPM runs on a virtual machine with hardened archlinux. Docker runs rootless there. NPM is my entrance to the network and then forwards to another virtual machine with my Nextcloud. This VM is also hardened and fail2ban is also running there. I may still have to take care of fail2ban on my NPM VM.

@nbently
I don't quite understand what you mean because my mounts work otherwise I couldn't access them from inside the container? Here is my stack that I deploy via Portainer.

version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    container_name: nginx-proxy
    restart: always
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
      - '993:993'
      #- '587:587'
    volumes:
      - nginx-proxy-data:/data
      - nginx-proxy-letsencrypt:/etc/letsencrypt
      - nginx-proxy-modules:/etc/nginx/modules

volumes:
  nginx-proxy-data:
    name: nginx-proxy-data
  nginx-proxy-letsencrypt:
    name: nginx-proxy-letsencrpyt
  nginx-proxy-modules:
    name: nginx-proxy-modules
<!-- gh-comment-id:2163442906 --> @maboxx commented on GitHub (Jun 12, 2024): I probably won't have time to go through the whole thing again until the weekend. @cruunnerr Thank you very much for the tips. My constellation is such that my NPM runs on a virtual machine with hardened archlinux. Docker runs rootless there. NPM is my entrance to the network and then forwards to another virtual machine with my Nextcloud. This VM is also hardened and fail2ban is also running there. I may still have to take care of fail2ban on my NPM VM. @nbently I don't quite understand what you mean because my mounts work otherwise I couldn't access them from inside the container? Here is my stack that I deploy via Portainer. ``` version: '3' services: app: image: 'jc21/nginx-proxy-manager:latest' container_name: nginx-proxy restart: always ports: - '80:80' - '81:81' - '443:443' - '993:993' #- '587:587' volumes: - nginx-proxy-data:/data - nginx-proxy-letsencrypt:/etc/letsencrypt - nginx-proxy-modules:/etc/nginx/modules volumes: nginx-proxy-data: name: nginx-proxy-data nginx-proxy-letsencrypt: name: nginx-proxy-letsencrpyt nginx-proxy-modules: name: nginx-proxy-modules ```
Author
Owner

@nbently commented on GitHub (Jun 14, 2024):

@maboxx that's what I was wondering, I see you're using volumes and not bind mounts. Theoretically that should work no problem but I bet that's where the issue is. Probably something permission related if I had to guess.

What happens if you create the geoip.log file manually (just an empty file)? I'd also check to make sure all the files you created have the same permissions as everything else & that the user running nginx has access to them.

<!-- gh-comment-id:2167055971 --> @nbently commented on GitHub (Jun 14, 2024): @maboxx that's what I was wondering, I see you're using volumes and not bind mounts. Theoretically that should work no problem but I bet that's where the issue is. Probably something permission related if I had to guess. What happens if you create the geoip.log file manually (just an empty file)? I'd also check to make sure all the files you created have the same permissions as everything else & that the user running nginx has access to them.
Author
Owner

@maboxx commented on GitHub (Jun 15, 2024):

Ok but when I compare the permissions from my files with the permissions of your file which seen above in your thread they are the same. What can be different between using bind mounts or volumes? What is exactly the difference and how can I set bind mounts?
I think another difference to your configuration is that my docker runs "rootless" but this should normally also not a problem....
I created the geoip.log manually. After restart and one day after now the .log have 0 bytes.
Maybe I just clone my VM and install NPM exactly like you did without rootless to see if it works? It remains strange. I don't think anything is configured wrong. Rootless and no bind mount should not be a problem.

@cruunnerr
Little digression about crowdsec. I would like to install crowdsec to secure NPM (docker). How exactly did you install and configure it? Do you have any links? Did you also install crowdsec as a docker or directly on the machine? How do I connect Crowdsec to the NPM Docker so that it secures NPM? Ideally, I would also like to completely back up the local machine at the same time, not just NPM?

<!-- gh-comment-id:2169137813 --> @maboxx commented on GitHub (Jun 15, 2024): Ok but when I compare the permissions from my files with the permissions of your file which seen above in your thread they are the same. What can be different between using bind mounts or volumes? What is exactly the difference and how can I set bind mounts? I think another difference to your configuration is that my docker runs "rootless" but this should normally also not a problem.... I created the geoip.log manually. After restart and one day after now the .log have 0 bytes. Maybe I just clone my VM and install NPM exactly like you did without rootless to see if it works? It remains strange. I don't think anything is configured wrong. Rootless and no bind mount should not be a problem. @cruunnerr Little digression about crowdsec. I would like to install crowdsec to secure NPM (docker). How exactly did you install and configure it? Do you have any links? Did you also install crowdsec as a docker or directly on the machine? How do I connect Crowdsec to the NPM Docker so that it secures NPM? Ideally, I would also like to completely back up the local machine at the same time, not just NPM?
Author
Owner

@itsbaraa commented on GitHub (Jul 31, 2024):

Have a look at bunkerweb. Has geoblock included and other waf rules.

Great Alternative.

<!-- gh-comment-id:2259754082 --> @itsbaraa commented on GitHub (Jul 31, 2024): > Have a look at bunkerweb. Has geoblock included and other waf rules. Great Alternative.
Author
Owner

@maboxx commented on GitHub (Aug 23, 2024):

@XDark187 Thanks for the tip. I still have no idea what exactly Bunkerweb is. I have heard of it but despite research I don't understand it exactly. Bunkweb is probably much more than "just" a proxy manager.

<!-- gh-comment-id:2307237373 --> @maboxx commented on GitHub (Aug 23, 2024): @XDark187 Thanks for the tip. I still have no idea what exactly Bunkerweb is. I have heard of it but despite research I don't understand it exactly. Bunkweb is probably much more than "just" a proxy manager.
Author
Owner

@itsbaraa commented on GitHub (Aug 23, 2024):

@XDark187 Thanks for the tip. I still have no idea what exactly Bunkerweb is. I have heard of it but despite research I don't understand it exactly. Bunkweb is probably much more than "just" a proxy manager.

Bunkerweb is a reverse proxy but with a lot of security features to protect your services by default, one of these security features is geoIP blocking and stopping brute force attacks and stopping bots, all security features are just toggles that you can enable or disable if you don't need them.

NPM requires so much work just to enable geoip blocking.

NPM is easier but less secure and bunkerweb is more secure but requires a bit of time to get it fully setup. IMO it's 100% worth it.

If you don't want to bother with NPM or Bunkerweb the easiest way is to use geoIP blocking with Cloudflare.

<!-- gh-comment-id:2307295930 --> @itsbaraa commented on GitHub (Aug 23, 2024): > @XDark187 Thanks for the tip. I still have no idea what exactly Bunkerweb is. I have heard of it but despite research I don't understand it exactly. Bunkweb is probably much more than "just" a proxy manager. Bunkerweb is a reverse proxy but with a lot of security features to protect your services by default, one of these security features is geoIP blocking and stopping brute force attacks and stopping bots, all security features are just toggles that you can enable or disable if you don't need them. NPM requires so much work just to enable geoip blocking. NPM is easier but less secure and bunkerweb is more secure but requires a bit of time to get it fully setup. IMO it's 100% worth it. If you don't want to bother with NPM or Bunkerweb the easiest way is to use geoIP blocking with Cloudflare.
Author
Owner

@webysther commented on GitHub (Oct 9, 2024):

I think this issue is fixed on https://github.com/NginxProxyManager/nginx-proxy-manager/pull/3766: https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module:

To enable the geoip2 module, you can create the custom configuration file /data/nginx/custom/root_top.conf and include the following snippet:

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;

I have tested and is working rock solid.

<!-- gh-comment-id:2403295060 --> @webysther commented on GitHub (Oct 9, 2024): I think this issue is fixed on https://github.com/NginxProxyManager/nginx-proxy-manager/pull/3766: https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module: To enable the geoip2 module, you can create the custom configuration file /data/nginx/custom/root_top.conf and include the following snippet: ```sh load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so; ``` I have tested and is working rock solid.
Author
Owner

@maboxx commented on GitHub (Oct 9, 2024):

Many thanks for the tip. Does this need to be configured in addition to the things above or instead?

<!-- gh-comment-id:2403305073 --> @maboxx commented on GitHub (Oct 9, 2024): Many thanks for the tip. Does this need to be configured in addition to the things above or instead?
Author
Owner

@webysther commented on GitHub (Oct 9, 2024):

Many thanks for the tip. Does this need to be configured in addition to the things above or instead?

Add also the database of geoip /data/GeoLite2-Country.mmdb on http_top.conf:

geoip2 /data/GeoLite2-Country.mmdb {
    $geoip2_data_country_iso_code country iso_code;
}

After you can create map on server block:

map $geoip2_data_country_iso_code $allowed_countries {
  default 0;
  BE 1;
  CA 1;
  AR 1;
  FI 1;
  NL 1;
  PT 1;
  US 1;
  DE 1;
}

map $geoip2_data_country_iso_code $allowed_brazil {
  default 0;
  BR 1;
}

map $geoip2_data_country_iso_code $allowed_italy {
  default 0;
  IT 1;
}
<!-- gh-comment-id:2403546852 --> @webysther commented on GitHub (Oct 9, 2024): > Many thanks for the tip. Does this need to be configured in addition to the things above or instead? Add also the database of geoip `/data/GeoLite2-Country.mmdb` on http_top.conf: ```nginx geoip2 /data/GeoLite2-Country.mmdb { $geoip2_data_country_iso_code country iso_code; } ``` After you can create map on server block: ```nginx map $geoip2_data_country_iso_code $allowed_countries { default 0; BE 1; CA 1; AR 1; FI 1; NL 1; PT 1; US 1; DE 1; } map $geoip2_data_country_iso_code $allowed_brazil { default 0; BR 1; } map $geoip2_data_country_iso_code $allowed_italy { default 0; IT 1; } ```
Author
Owner

@webysther commented on GitHub (Oct 11, 2024):

Thank you very much @cruunnerr @nbently @phyte22 for your patience and effort, I will check again point by point as soon as I have time.

You're very welcome. Please keep in mind, that GeoIP-Blocking is a nice thing to have, but doesn't free your server from getting attacked. It is good for blocking bots and crawlers and surely prevents your proxy hosts from being inspected from several countries. But attackers often use bot nets and have several bots in different countries. So it kind of protects you from getting attacked from "everywhere". But I would definitely recommend you to also install crowdsec (or at least fail2ban) on your bare NPM-Server. Since crowdsec detects basically even before the packets reaches your NPM-Docker instance and can effectively protect against many kinds of attacks on vulnerabilities or exploits. Just imagine NPM or your OS has a vulnerability which can be attacked even before packets reach your Hosts or your NPM Docker instance. For example my crowdsec instance detected around 25 scenarios and blocked the IP's, just for today! For the hole June I have actually 473 blocked scenarios (85 of them from Germany, which even wouldn't have been blocked via GeoIP).

Just think about it ;)

Good point, just to add some on this. The main point of using geoip is about reduce the attack surface. The big takes about security is more about this:

  • Keep a SYN-flood (DoS) protection on router
  • Block on firewall of router or before any reverse proxy the bogons and firehol level 1
  • If there no host with worldwide need, keep the geoip in firewall and not in reverse proxy
  • Any exposed host keep exploit protection and SSO like authelia
  • Never use DMZ, block all and enable by need in firewall

Never keep just one layer of security.

<!-- gh-comment-id:2407291197 --> @webysther commented on GitHub (Oct 11, 2024): > > Thank you very much @cruunnerr @nbently @phyte22 for your patience and effort, I will check again point by point as soon as I have time. > > You're very welcome. Please keep in mind, that GeoIP-Blocking is a nice thing to have, but doesn't free your server from getting attacked. It is good for blocking bots and crawlers and surely prevents your proxy hosts from being inspected from several countries. But attackers often use bot nets and have several bots in different countries. So it kind of protects you from getting attacked from "everywhere". But I would definitely recommend you to also install crowdsec (or at least fail2ban) on your bare NPM-Server. Since crowdsec detects basically even before the packets reaches your NPM-Docker instance and can effectively protect against many kinds of attacks on vulnerabilities or exploits. Just imagine NPM or your OS has a vulnerability which can be attacked even before packets reach your Hosts or your NPM Docker instance. For example my crowdsec instance detected around 25 scenarios and blocked the IP's, just for today! For the hole June I have actually 473 blocked scenarios (85 of them from Germany, which even wouldn't have been blocked via GeoIP). > > Just think about it ;) Good point, just to add some on this. The main point of using geoip is about reduce the attack surface. The big takes about security is more about this: - Keep a SYN-flood (DoS) protection on router - Block on firewall of router or before any reverse proxy the bogons and firehol level 1 - If there no host with worldwide need, keep the geoip in firewall and not in reverse proxy - Any exposed host keep exploit protection and SSO like authelia - Never use DMZ, block all and enable by need in firewall Never keep just one layer of security.
Author
Owner

@maboxx commented on GitHub (Oct 12, 2024):

Thank you very much for all the information. I haven't had time yet, but I'm going to try the topic again soon and hopefully I'll get it right and working.

<!-- gh-comment-id:2408441264 --> @maboxx commented on GitHub (Oct 12, 2024): Thank you very much for all the information. I haven't had time yet, but I'm going to try the topic again soon and hopefully I'll get it right and working.
Author
Owner

@tanmaychimurkar commented on GitHub (Oct 15, 2024):

Hi there, i also tried the comment as per @phyte22 here https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2130372959 , and setup everything according to the same volume mounts.

The geoip.log file appears, and it shows the correct iso country code and whether or not it is allowed. The only issue i have is when I put the following in the advanced configuration of the proxy_host:

if ($allowed_countries = 0) {
        return 444; 
}

My proxy host goes offline. Moreover, the logs from the npm container show the following:

[10/15/2024] [3:52:59 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:52:59 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:52:59 PM] [Nginx    ] › ℹ  info      Reloading Nginx
[10/15/2024] [3:52:59 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -s reload
[10/15/2024] [3:53:56 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Deleting file: /data/nginx/proxy_host/8.conf
[10/15/2024] [3:53:57 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Deleting file: /data/nginx/proxy_host/8.conf
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Deleting file: /data/nginx/proxy_host/8.conf.err
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Could not delete file: {
  "errno": -2,
  "code": "ENOENT",
  "syscall": "unlink",
  "path": "/data/nginx/proxy_host/8.conf.err"
}
[10/15/2024] [3:53:57 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:53:57 PM] [Nginx    ] › ℹ  info      Reloading Nginx
[10/15/2024] [3:53:57 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -s reload

(the last logs, where 8.conf.err is being deleted is after updating the server block in the Advanced tab of proxy_host)

When I then go to /data/nginx/proxy_host on my local machine, the 8.conf proxy_host file itself is gone. When I revert the changes in the Advanced block, the 8.conf proxy_host file comes back.

The fallback_error.log shows the followign:

2024/10/15 15:56:17 [error] 234#234: *1055 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost-nginx-proxy-manager, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:80/favicon.ico", host: "xxx.xxx.xxx.xxx"

The proxy-host-8_error.log shows nothing to point me in the right direction. Anyone know how to resolve this?

<!-- gh-comment-id:2414013880 --> @tanmaychimurkar commented on GitHub (Oct 15, 2024): Hi there, i also tried the comment as per @phyte22 here https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2130372959 , and setup everything according to the same volume mounts. The `geoip.log` file appears, and it shows the correct iso country code and whether or not it is allowed. The only issue i have is when I put the following in the advanced configuration of the `proxy_host`: ``` if ($allowed_countries = 0) { return 444; } ``` My proxy host goes `offline`. Moreover, the logs from the `npm` container show the following: ``` [10/15/2024] [3:52:59 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" [10/15/2024] [3:52:59 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" [10/15/2024] [3:52:59 PM] [Nginx ] › ℹ info Reloading Nginx [10/15/2024] [3:52:59 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -s reload [10/15/2024] [3:53:56 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Deleting file: /data/nginx/proxy_host/8.conf [10/15/2024] [3:53:57 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Deleting file: /data/nginx/proxy_host/8.conf [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Deleting file: /data/nginx/proxy_host/8.conf.err [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Could not delete file: { "errno": -2, "code": "ENOENT", "syscall": "unlink", "path": "/data/nginx/proxy_host/8.conf.err" } [10/15/2024] [3:53:57 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" [10/15/2024] [3:53:57 PM] [Nginx ] › ℹ info Reloading Nginx [10/15/2024] [3:53:57 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -s reload (the last logs, where 8.conf.err is being deleted is after updating the server block in the Advanced tab of proxy_host) ``` When I then go to `/data/nginx/proxy_host` on my local machine, the `8.conf` proxy_host file itself is gone. When I revert the changes in the Advanced block, the `8.conf` proxy_host file comes back. The `fallback_error.log` shows the followign: ``` 2024/10/15 15:56:17 [error] 234#234: *1055 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost-nginx-proxy-manager, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:80/favicon.ico", host: "xxx.xxx.xxx.xxx" ``` The `proxy-host-8_error.log` shows nothing to point me in the right direction. Anyone know how to resolve this?
Author
Owner

@webysther commented on GitHub (Oct 15, 2024):

Hi there, i also tried the comment as per @phyte22 here #46 (comment) , and setup everything according to the same volume mounts.

The geoip.log file appears, and it shows the correct iso country code and whether or not it is allowed. The only issue i have is when I put the following in the advanced configuration of the proxy_host:

if ($allowed_countries = 0) {
        return 444; 
}

My proxy host goes offline. Moreover, the logs from the npm container show the following:

[10/15/2024] [3:52:59 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:52:59 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:52:59 PM] [Nginx    ] › ℹ  info      Reloading Nginx
[10/15/2024] [3:52:59 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -s reload
[10/15/2024] [3:53:56 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Deleting file: /data/nginx/proxy_host/8.conf
[10/15/2024] [3:53:57 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Deleting file: /data/nginx/proxy_host/8.conf
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Deleting file: /data/nginx/proxy_host/8.conf.err
[10/15/2024] [3:53:57 PM] [Nginx    ] › ⬤  debug     Could not delete file: {
  "errno": -2,
  "code": "ENOENT",
  "syscall": "unlink",
  "path": "/data/nginx/proxy_host/8.conf.err"
}
[10/15/2024] [3:53:57 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -t -g "error_log off;"
[10/15/2024] [3:53:57 PM] [Nginx    ] › ℹ  info      Reloading Nginx
[10/15/2024] [3:53:57 PM] [Global   ] › ⬤  debug     CMD: /usr/sbin/nginx -s reload

(the last logs, where 8.conf.err is being deleted is after updating the server block in the Advanced tab of proxy_host)

When I then go to /data/nginx/proxy_host on my local machine, the 8.conf proxy_host file itself is gone. When I revert the changes in the Advanced block, the 8.conf proxy_host file comes back.

The fallback_error.log shows the followign:

2024/10/15 15:56:17 [error] 234#234: *1055 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost-nginx-proxy-manager, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:80/favicon.ico", host: "xxx.xxx.xxx.xxx"

The proxy-host-8_error.log shows nothing to point me in the right direction. Anyone know how to resolve this?

You have created in some how a loop condition that make you network going in a block state and reset. Check if you error page have a location that check again against the geoip or if there a loopback in somewhere. To help fix this, isolate and enable one host at time.

<!-- gh-comment-id:2414941692 --> @webysther commented on GitHub (Oct 15, 2024): > Hi there, i also tried the comment as per @phyte22 here [#46 (comment)](https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2130372959) , and setup everything according to the same volume mounts. > > The `geoip.log` file appears, and it shows the correct iso country code and whether or not it is allowed. The only issue i have is when I put the following in the advanced configuration of the `proxy_host`: > > ``` > if ($allowed_countries = 0) { > return 444; > } > ``` > > My proxy host goes `offline`. Moreover, the logs from the `npm` container show the following: > > ``` > [10/15/2024] [3:52:59 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" > [10/15/2024] [3:52:59 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" > [10/15/2024] [3:52:59 PM] [Nginx ] › ℹ info Reloading Nginx > [10/15/2024] [3:52:59 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -s reload > [10/15/2024] [3:53:56 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" > [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Deleting file: /data/nginx/proxy_host/8.conf > [10/15/2024] [3:53:57 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" > [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Deleting file: /data/nginx/proxy_host/8.conf > [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Deleting file: /data/nginx/proxy_host/8.conf.err > [10/15/2024] [3:53:57 PM] [Nginx ] › ⬤ debug Could not delete file: { > "errno": -2, > "code": "ENOENT", > "syscall": "unlink", > "path": "/data/nginx/proxy_host/8.conf.err" > } > [10/15/2024] [3:53:57 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -t -g "error_log off;" > [10/15/2024] [3:53:57 PM] [Nginx ] › ℹ info Reloading Nginx > [10/15/2024] [3:53:57 PM] [Global ] › ⬤ debug CMD: /usr/sbin/nginx -s reload > > (the last logs, where 8.conf.err is being deleted is after updating the server block in the Advanced tab of proxy_host) > ``` > > When I then go to `/data/nginx/proxy_host` on my local machine, the `8.conf` proxy_host file itself is gone. When I revert the changes in the Advanced block, the `8.conf` proxy_host file comes back. > > The `fallback_error.log` shows the followign: > > ``` > 2024/10/15 15:56:17 [error] 234#234: *1055 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost-nginx-proxy-manager, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:80/favicon.ico", host: "xxx.xxx.xxx.xxx" > ``` > > The `proxy-host-8_error.log` shows nothing to point me in the right direction. Anyone know how to resolve this? You have created in some how a loop condition that make you network going in a block state and reset. Check if you error page have a location that check again against the geoip or if there a loopback in somewhere. To help fix this, isolate and enable one host at time.
Author
Owner

@gioman commented on GitHub (Nov 26, 2024):

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;

After some trial and error I have been able to make geoip working for proxy hosts. Anyway the fact that docs say that there is also this module

load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so

seems to suggest that this approach can also be used for streams (am I wrong?). Anyway I'm struggling because in streams conf files generated by NPM, if something like

if ($allowed_countries = 0) {
        return 444; 
}

is added then an error like

nginx: [emerg] "if" directive is not allowed here in /data/nginx/stream/14.conf:11

is returned. If conditionals/if cannot be used there, how the same as proxy hosts can be achieved?

Thanks in advance

<!-- gh-comment-id:2501771501 --> @gioman commented on GitHub (Nov 26, 2024): > ```shell > load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; > load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so; > ``` After some trial and error I have been able to make geoip working for proxy hosts. Anyway the fact that docs say that there is also this module `load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so` seems to suggest that this approach can also be used for streams (am I wrong?). Anyway I'm struggling because in streams conf files generated by NPM, if something like ``` if ($allowed_countries = 0) { return 444; } ``` is added then an error like `nginx: [emerg] "if" directive is not allowed here in /data/nginx/stream/14.conf:11` is returned. If conditionals/if cannot be used there, how the same as proxy hosts can be achieved? Thanks in advance
Author
Owner

@gioman commented on GitHub (Nov 30, 2024):

Thanks in advance

I did not find a solution within NPM, but I possibly found one that seems to work and that must be applied on the host. I'm not by any mean an expert of NPM and UFW/IPTABLE, so please be kind if the following has something that is wrong. Suggestions and corrections are welcome.

First I installed the geoip module on the host, I used this guide https://www.seenlyst.com/blog/geo-blocking-ufw-iptables/ which I followed with success in other cases not involving NPM.

Then I also installed ufw-docker https://github.com/chaifeng/ufw-docker so to be able to define firewall rules on the host that also apply to the NPM container.

Then:

start UFW on the host, be careful to add a rule beforehand that will not cut you off from SSH, something like

ufw allow 22
ufw enable

Then

ufw-docker allow npm-app-1 443

this allows httpS traffic for the proxy hosts. Then:

sudo iptables -A ufw-user-forward -p tcp -m geoip --src-cc IT --dport 1234 -j ACCEPT

to allow (or deny, if you use "DROP" instead of "ACCEPT") IPs from a whatever country code to reach your stream port.

This rule is not persistent to reboots (and probably also UFW restarts/reloads(, I'm not sure what is the best way to make it persistent but for now I'm happy applying it with a script after the host reboot.

I have also added NPM as a proxy host in itself, so to be able reach it with its domain I had to add this rules too:

ufw-docker allow npm-app-1 81
sudo ufw allow from 172.18.0.0/16 to 65.21.179.35 port 81
sudo ufw allow from 172.18.0.0/16 to 65.21.179.35 port 443

The first one is necessary also to allow reach the NPM GUI with the host IP on port 81.

<!-- gh-comment-id:2508943138 --> @gioman commented on GitHub (Nov 30, 2024): > Thanks in advance I did not find a solution within NPM, but I possibly found one that seems to work and that must be applied on the host. I'm not by any mean an expert of NPM and UFW/IPTABLE, so please be kind if the following has something that is wrong. Suggestions and corrections are welcome. First I installed the geoip module on the host, I used this guide https://www.seenlyst.com/blog/geo-blocking-ufw-iptables/ which I followed with success in other cases not involving NPM. Then I also installed ufw-docker https://github.com/chaifeng/ufw-docker so to be able to define firewall rules on the host that also apply to the NPM container. Then: start UFW on the host, be careful to add a rule beforehand that will not cut you off from SSH, something like ``` ufw allow 22 ufw enable ``` Then `ufw-docker allow npm-app-1 443` this allows httpS traffic for the proxy hosts. Then: `sudo iptables -A ufw-user-forward -p tcp -m geoip --src-cc IT --dport 1234 -j ACCEPT` to allow (or deny, if you use "DROP" instead of "ACCEPT") IPs from a whatever country code to reach your stream port. This rule is not persistent to reboots (and probably also UFW restarts/reloads(, I'm not sure what is the best way to make it persistent but for now I'm happy applying it with a script after the host reboot. I have also added NPM as a proxy host in itself, so to be able reach it with its domain I had to add this rules too: ``` ufw-docker allow npm-app-1 81 sudo ufw allow from 172.18.0.0/16 to 65.21.179.35 port 81 sudo ufw allow from 172.18.0.0/16 to 65.21.179.35 port 443 ``` The first one is necessary also to allow reach the NPM GUI with the host IP on port 81.
Author
Owner

@Vaalus commented on GitHub (Jan 8, 2025):

@cruunnerr's comment.

I just logged in to say thank you! I tried your config and it immediately worked. Really appreciate it :)

EDIT: Just wanted to mention something, I couldn't access my site because I'm in the same Lan network. Had to modify the config files this way to get it to work:

http_top.conf

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
}

map $geoip2_data_country_iso_code $allowed_country {
    default no;
    DE yes;
#^ Germany example.

}

# Define private IP ranges (LAN IPs)
geo $lan-ip {
    default no;
    10.0.0.0/8 yes;
    172.16.0.0/12 yes;
    192.168.0.0/16 yes;
    127.0.0.1 yes;
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_country_iso_code" "$allowed_country"';
           #'"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

server_proxy.conf

if ($lan-ip = yes) { set $allowed_country yes; }
if ($allowed_country = no) { return 444; }

access_log /data/logs/geoip.log geoip;
<!-- gh-comment-id:2576569835 --> @Vaalus commented on GitHub (Jan 8, 2025): > @cruunnerr's [comment](https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2159164330). > I just logged in to say thank you! I tried your config and it immediately worked. Really appreciate it :) EDIT: Just wanted to mention something, I couldn't access my site because I'm in the same Lan network. Had to modify the config files this way to get it to work: ### http_top.conf ``` geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } map $geoip2_data_country_iso_code $allowed_country { default no; DE yes; #^ Germany example. } # Define private IP ranges (LAN IPs) geo $lan-ip { default no; 10.0.0.0/8 yes; 172.16.0.0/12 yes; 192.168.0.0/16 yes; 127.0.0.1 yes; } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_country_iso_code" "$allowed_country"'; #'"$geoip2_data_city_name" "$geoip2_data_country_iso_code"'; ``` ### server_proxy.conf ``` if ($lan-ip = yes) { set $allowed_country yes; } if ($allowed_country = no) { return 444; } access_log /data/logs/geoip.log geoip; ```
Author
Owner

@webysther commented on GitHub (Jan 8, 2025):

@jc21 this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? @teodorch85 i think you can close I change to use the geoip and works perfect

<!-- gh-comment-id:2577568207 --> @webysther commented on GitHub (Jan 8, 2025): @jc21 this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? @teodorch85 i think you can close I change to use the geoip and works perfect
Author
Owner

@mauroreggio commented on GitHub (Jan 17, 2025):

@jc21 this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? @teodorch85 i think you can close I change to use the geoip and works perfect

I webysther. Sorry for my question.
I follow the link and i simply read to add 2 line in a new config file. I start NPM and no error appears.
But ... how i can use geoip2 module?
Nothing in webconfig interface.
Nothing new in log.
Where i can work for put geoip2 module usage config? (i'm intrested in deny some location access and log IP access location).
Search many for example but not find nothing.
Thanks.

<!-- gh-comment-id:2598613012 --> @mauroreggio commented on GitHub (Jan 17, 2025): > [@jc21](https://github.com/jc21) this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? [@teodorch85](https://github.com/teodorch85) i think you can close I change to use the geoip and works perfect I webysther. Sorry for my question. I follow the link and i simply read to add 2 line in a new config file. I start NPM and no error appears. But ... how i can use geoip2 module? Nothing in webconfig interface. Nothing new in log. Where i can work for put geoip2 module usage config? (i'm intrested in deny some location access and log IP access location). Search many for example but not find nothing. Thanks.
Author
Owner

@webysther commented on GitHub (Jan 17, 2025):

@jc21 this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? @teodorch85 i think you can close I change to use the geoip and works perfect

I webysther. Sorry for my question. I follow the link and i simply read to add 2 line in a new config file. I start NPM and no error appears. But ... how i can use geoip2 module? Nothing in webconfig interface. Nothing new in log. Where i can work for put geoip2 module usage config? (i'm intrested in deny some location access and log IP access location). Search many for example but not find nothing. Thanks.

Please read the comments here, there few examples like @Vaalus next my last comment.

<!-- gh-comment-id:2598766585 --> @webysther commented on GitHub (Jan 17, 2025): > > [@jc21](https://github.com/jc21) this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? [@teodorch85](https://github.com/teodorch85) i think you can close I change to use the geoip and works perfect > > I webysther. Sorry for my question. I follow the link and i simply read to add 2 line in a new config file. I start NPM and no error appears. But ... how i can use geoip2 module? Nothing in webconfig interface. Nothing new in log. Where i can work for put geoip2 module usage config? (i'm intrested in deny some location access and log IP access location). Search many for example but not find nothing. Thanks. Please read the comments here, there few examples like @Vaalus next my last comment.
Author
Owner

@mauroreggio commented on GitHub (Jan 17, 2025):

@jc21 this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? @teodorch85 i think you can close I change to use the geoip and works perfect

I webysther. Sorry for my question. I follow the link and i simply read to add 2 line in a new config file. I start NPM and no error appears. But ... how i can use geoip2 module? Nothing in webconfig interface. Nothing new in log. Where i can work for put geoip2 module usage config? (i'm intrested in deny some location access and log IP access location). Search many for example but not find nothing. Thanks.

Please read the comments here, there few examples like @Vaalus next my last comment.

I just work now on it ... and sorry because i not watch good before.
I try but in the "start container log" seems that NGPM not find the database

nginxpm-1 | ❯ Starting nginx ... nginxpm-1 | nginx: [emerg] MMDB_open("/data/geoip2db/GeoLite2-Country.mmdb") failed - Error opening the specified MaxMind DB file in /data/nginx/custom/http_top.conf:1

I think is because the first line of http_top.conf

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {

but where is the database of geoip2 with this config?

<!-- gh-comment-id:2598773687 --> @mauroreggio commented on GitHub (Jan 17, 2025): > > > [@jc21](https://github.com/jc21) this is not fixed with https://nginxproxymanager.com/advanced-config/#enabling-the-geoip2-module ? [@teodorch85](https://github.com/teodorch85) i think you can close I change to use the geoip and works perfect > > > > > > I webysther. Sorry for my question. I follow the link and i simply read to add 2 line in a new config file. I start NPM and no error appears. But ... how i can use geoip2 module? Nothing in webconfig interface. Nothing new in log. Where i can work for put geoip2 module usage config? (i'm intrested in deny some location access and log IP access location). Search many for example but not find nothing. Thanks. > > Please read the comments here, there few examples like [@Vaalus](https://github.com/Vaalus) next my last comment. I just work now on it ... and sorry because i not watch good before. I try but in the "start container log" seems that NGPM not find the database ` nginxpm-1 | ❯ Starting nginx ... nginxpm-1 | nginx: [emerg] MMDB_open("/data/geoip2db/GeoLite2-Country.mmdb") failed - Error opening the specified MaxMind DB file in /data/nginx/custom/http_top.conf:1 ` I think is because the first line of http_top.conf `geoip2 /data/geoip2db/GeoLite2-Country.mmdb {` but where is the database of geoip2 with this config?
Author
Owner

@mauroreggio commented on GitHub (Jan 17, 2025):

I think i understand something (let me know if is true).

  • GeoIP database must be download, update, maintained "out of NGPM container"
  • For this is necessary register an account in Maxmind and use all the tools that Maxmind makes available for this purpose.
    This is first step.
    Once i've obtained my database fresh copy (GeoLite2-Country.mmdb) i can succesfully run NGPM container with no errors and with http_top.conf added Custom Config File

geoip2 /data/GeoLite2-Country.mmdb {
    $geoip2_data_country_iso_code country iso_code;
}

Now i'm stuck in the next step that i read more up in https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2403546852

After you can create map on server block:

map $geoip2_data_country_iso_code $allowed_italy {
  default 0;
  IT 1;
}

... where i must put this?
I try add in "Advanced" tab of my "Edit - Proxy Host" page of the webconfig page ... but this put the Proxy Host in error.

Image

EDIT: i add the block in http_top.conf
This works good and log all access in /data/logs/geoip.log
But in this way is for ALL "Proxy Hosts" that NGPM serve.
Is possible via web interface have the same result but maybe different settings for any "Proxy Host"? (maybe using the "Advanced" tab that i show in the image before?)

<!-- gh-comment-id:2598904626 --> @mauroreggio commented on GitHub (Jan 17, 2025): I think i understand something (let me know if is true). - GeoIP database must be download, update, maintained "out of NGPM container" - For this is necessary register an account in Maxmind and use all the tools that Maxmind makes available for this purpose. This is first step. Once i've obtained my database fresh copy (GeoLite2-Country.mmdb) i can succesfully run NGPM container with no errors and with http_top.conf added Custom Config File ``` geoip2 /data/GeoLite2-Country.mmdb { $geoip2_data_country_iso_code country iso_code; } ``` Now i'm stuck in the next step that i read more up in [https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2403546852](https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2403546852) After you can create map on server block: ``` map $geoip2_data_country_iso_code $allowed_italy { default 0; IT 1; } ``` ... where i must put this? I try add in "Advanced" tab of my "Edit - Proxy Host" page of the webconfig page ... but this put the Proxy Host in error. ![Image](https://github.com/user-attachments/assets/14a7aa1b-82a6-4243-9ae3-84c9f8255a40) EDIT: i add the block in http_top.conf This works good and log all access in /data/logs/geoip.log But in this way is for ALL "Proxy Hosts" that NGPM serve. Is possible via web interface have the same result but maybe different settings for any "Proxy Host"? (maybe using the "Advanced" tab that i show in the image before?)
Author
Owner

@adamoutler commented on GitHub (Feb 14, 2025):

Can someone please expand the docs? After enabling geoip, there should be a log of IPs at a minimum. It appears that enabling geoip requires you to follow some other guide to enable geoip functionality. The official guide just enables modules which do nothing on their own.

<!-- gh-comment-id:2659252317 --> @adamoutler commented on GitHub (Feb 14, 2025): Can someone please expand the docs? After enabling geoip, there should be a log of IPs at a minimum. It appears that enabling geoip requires you to follow some other guide to enable geoip functionality. The official guide just enables modules which do nothing on their own.
Author
Owner

@gilbrotheraway commented on GitHub (Feb 18, 2025):

Can someone please expand the docs? After enabling geoip, there should be a log of IPs at a minimum. It appears that enabling geoip requires you to follow some other guide to enable geoip functionality. The official guide just enables modules which do nothing on their own.

i second this, docs are pretty vague

<!-- gh-comment-id:2665931323 --> @gilbrotheraway commented on GitHub (Feb 18, 2025): > Can someone please expand the docs? After enabling geoip, there should be a log of IPs at a minimum. It appears that enabling geoip requires you to follow some other guide to enable geoip functionality. The official guide just enables modules which do nothing on their own. i second this, docs are pretty vague
Author
Owner

@gioman commented on GitHub (Feb 18, 2025):

Can someone please expand the docs?

I don't have time to make a PR to docs, but I leave here my notes, feel free to use them for a pull request against docs.

Add to docker-compose.yml (in volumes):

      - /mnt/geoip/GeoLite2-City.mmdb:/data/geoip2db/GeoLite2-City.mmdb
      - /mnt/geoip/GeoLite2-Country.mmdb:/data/geoip2db/GeoLite2-Country.mmdb
      - /mnt/nginx_conf/enable_ngx_http_geoip2_module.conf:/etc/nginx/modules/enable_ngx_http_geoip2_module.conf
      - /mnt/nginx_conf/http_top.conf:/data/nginx/custom/http_top.conf
      - /mnt/nginx_conf/server_proxy.conf:/data/nginx/custom/server_proxy.conf

Of course you need to download first the GeoLite databases from the MaxMind web site and put them in a proper location on the host, in the above example "/mnt/geoip/".

enable_ngx_http_geoip2_module.conf contains

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;

http_top.conf contains something along the lines:

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
#$geoip2_data_city_name city names en;
}

map $geoip2_data_country_iso_code $allowed_country {
   default: no;
   PT yes;
}

map $geoip2_data_country_iso_code $allowed_italy {
  default: no;
  IT yes;
}

map $geoip2_data_country_iso_code $allowed_portugal {
  default: no;
  PT yes;
}

map $geoip2_data_country_iso_code $disallowed_countries {
   default: no;
   US yes;
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_country_iso_code" "$allowed_country"';

server_proxy.conf contains

access_log /data/logs/geoip.log geoip;

Take down / up the container, enter in it and reload ngnix to see if there are errors:

docker compose down && docker compose up -d
docker exec -it npm-app-1 bash
nginx -s reload

To configure the setings for a specific proxy host, enter the container:

docker exec -it npm-app-1 bash

edit /data/nginx/proxy_host/XXX.conf (where "XXX" is the id of the proxy host):

vi /data/nginx/proxy_host/XXX.conf

...
...
...
server_name test.mydomain.com;

if ($disallowed_countries = "yes") {
#return 444;
return 301 https://test.mydomain.com$request_uri;
}

#map $geoip2_data_country_iso_code $allowed_country {
  default: no;
  DE yes; # Germany
#}

...
...
...

nginx -s reload

<!-- gh-comment-id:2666538592 --> @gioman commented on GitHub (Feb 18, 2025): > Can someone please expand the docs? I don't have time to make a PR to docs, but I leave here my notes, feel free to use them for a pull request against docs. Add to docker-compose.yml (in volumes): ``` - /mnt/geoip/GeoLite2-City.mmdb:/data/geoip2db/GeoLite2-City.mmdb - /mnt/geoip/GeoLite2-Country.mmdb:/data/geoip2db/GeoLite2-Country.mmdb - /mnt/nginx_conf/enable_ngx_http_geoip2_module.conf:/etc/nginx/modules/enable_ngx_http_geoip2_module.conf - /mnt/nginx_conf/http_top.conf:/data/nginx/custom/http_top.conf - /mnt/nginx_conf/server_proxy.conf:/data/nginx/custom/server_proxy.conf ``` Of course you need to download first the GeoLite databases from the MaxMind web site and put them in a proper location on the host, in the above example "/mnt/geoip/". `enable_ngx_http_geoip2_module.conf `contains ``` load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so; ``` `http_top.conf` contains something along the lines: ``` geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; #$geoip2_data_city_name city names en; } map $geoip2_data_country_iso_code $allowed_country { default: no; PT yes; } map $geoip2_data_country_iso_code $allowed_italy { default: no; IT yes; } map $geoip2_data_country_iso_code $allowed_portugal { default: no; PT yes; } map $geoip2_data_country_iso_code $disallowed_countries { default: no; US yes; } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_country_iso_code" "$allowed_country"'; ``` `server_proxy.conf` contains `access_log /data/logs/geoip.log geoip;` Take down / up the container, enter in it and reload ngnix to see if there are errors: ``` docker compose down && docker compose up -d docker exec -it npm-app-1 bash nginx -s reload ``` To configure the setings for a specific proxy host, enter the container: `docker exec -it npm-app-1 bash` edit `/data/nginx/proxy_host/XXX.conf` (where "XXX" is the id of the proxy host): `vi /data/nginx/proxy_host/XXX.conf` ``` ... ... ... server_name test.mydomain.com; if ($disallowed_countries = "yes") { #return 444; return 301 https://test.mydomain.com$request_uri; } #map $geoip2_data_country_iso_code $allowed_country { default: no; DE yes; # Germany #} ... ... ... ``` `nginx -s reload`
Author
Owner

@maboxx commented on GitHub (Apr 26, 2025):

Hello again,
I only now had the nerve to look at the topic again and I can hardly believe I'm a little further along.
I came across it via @gioman last post, thank you very much!

The problem with me seems to have been that my http_top.conf and server_proxy.conf was in /data/custom and not in /data/nginx/custom. I move this to files to /data/nginx/custom and now /data/log/geoip.log is finally created and I can see my connections in it 👍

I have now checked everything again and compared it with the information @cruunnerr was given to me (link)

I would like to show where I currently stand because I am not sure whether it will work in the end and not allowed countrys will be blocked.

Add to docker-compose.yml (in volumes):

      - nginx-proxy-data:/data
      - nginx-proxy-letsencrypt:/etc/letsencrypt

/data/nginx/custom/http_top.conf

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
}

map $geoip2_data_country_iso_code $allowed_country {
   default: no;
   DE yes; # Germany
}

log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_country_iso_code" "$allowed_country"';

/data/nginx/custom/server_proxy.conf

access_log /data/logs/geoip.log geoip;

/data/nginx/custom/root_top.conf

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;

The GeoLite2-Country.mmdb is downloaded and located to /data/geoip2db

I have added the following to each of my proxy hosts via the WebGui using the Advanced tab.

if ($allowed_country = no) {
        return 444;
}

And for the first time, these do not turn red after saving but remain green. I am still considering whether I want to do it like @cruunnerr and enter this in the server_proxy.conf.

In the log I can now see that I am accessing via my IP which comes from my country.

My question now is how can I test whether US is blocked, for example? Actually just change the country XX in the http_top.conf and test again from my device? I did that but the access still works to my proxy host behind the npm....

EDIT:
I found the failure....
Here was a colon after “default” this must be removed then it works.

map $geoip2_data_country_iso_code $allowed_country {
   default no;
   DE yes; # Germany
}

And I testet it now over an VPN connection from NL and it works fine :-) NL is blocked.

Now I have the problem that I can no longer access my LAN with 192.168.1.1. The solution from @Vaalus and @cruunnerr does not help me.
Could someone help me with this again?
My current http_top.conf

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
}


map $geoip2_data_country_iso_code $allowed_country {
   default no;
   # Local LAN
   192.168.1.0/24 yes;
   10.0.0.0/8 yes;
   172.16.0.0/12 yes;
   127.0.0.1 yes;
   # Germany
   DE yes;
}
                                                            
log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'     
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'           
           '"$geoip2_data_country_iso_code" "$allowed_country"';

EDIT again:
I have now managed to ensure that my LAN router IP is no longer blocked. I can therefore access from inside my LAN to the defined Proxy_hosts.
This is how I did it, no idea what I'm doing but it works. Here my http_top.conf:

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_iso_code country iso_code;
}


geo $allowed_ip {
        default no;             
        192.168.1.1 yes;    
}

map $geoip2_data_country_iso_code $allowed_country {
   default $allowed_ip;
   DE yes; # Germany
}


log_format geoip '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_country_iso_code" "$allowed_country"';
<!-- gh-comment-id:2831978187 --> @maboxx commented on GitHub (Apr 26, 2025): Hello again, I only now had the nerve to look at the topic again and I can hardly believe I'm a little further along. I came across it via @gioman last post, thank you very much! The problem with me seems to have been that my `http_top.conf` and `server_proxy.conf` was in `/data/custom` and not in `/data/nginx/custom`. I move this to files to `/data/nginx/custom` and now `/data/log/geoip.log` is finally created and I can see my connections in it 👍 I have now checked everything again and compared it with the information @cruunnerr was given to me [(link)](https://github.com/NginxProxyManager/nginx-proxy-manager/issues/46#issuecomment-2159164330) I would like to show where I currently stand because I am not sure whether it will work in the end and not allowed countrys will be blocked. Add to docker-compose.yml (in volumes): ``` - nginx-proxy-data:/data - nginx-proxy-letsencrypt:/etc/letsencrypt ``` /data/nginx/custom/http_top.conf ``` geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } map $geoip2_data_country_iso_code $allowed_country { default: no; DE yes; # Germany } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_country_iso_code" "$allowed_country"'; ``` /data/nginx/custom/server_proxy.conf ``` access_log /data/logs/geoip.log geoip; ``` /data/nginx/custom/root_top.conf ``` load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so; ``` The `GeoLite2-Country.mmdb` is downloaded and located to `/data/geoip2db` I have added the following to each of my proxy hosts via the WebGui using the Advanced tab. ``` if ($allowed_country = no) { return 444; } ``` And for the first time, these do not turn red after saving but remain green. I am still considering whether I want to do it like @cruunnerr and enter this in the server_proxy.conf. In the log I can now see that I am accessing via my IP which comes from my country. My question now is how can I test whether US is blocked, for example? Actually just change the country XX in the `http_top.conf `and test again from my device? I did that but the access still works to my proxy host behind the npm.... EDIT: I found the failure.... Here was a colon after “default” this must be removed then it works. ``` map $geoip2_data_country_iso_code $allowed_country { default no; DE yes; # Germany } ``` And I testet it now over an VPN connection from NL and it works fine :-) NL is blocked. Now I have the problem that I can no longer access my LAN with 192.168.1.1. The solution from @Vaalus and @cruunnerr does not help me. Could someone help me with this again? My current http_top.conf ``` geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } map $geoip2_data_country_iso_code $allowed_country { default no; # Local LAN 192.168.1.0/24 yes; 10.0.0.0/8 yes; 172.16.0.0/12 yes; 127.0.0.1 yes; # Germany DE yes; } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_country_iso_code" "$allowed_country"'; ``` EDIT again: I have now managed to ensure that my LAN router IP is no longer blocked. I can therefore access from inside my LAN to the defined Proxy_hosts. This is how I did it, no idea what I'm doing but it works. Here my http_top.conf: ``` geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } geo $allowed_ip { default no; 192.168.1.1 yes; } map $geoip2_data_country_iso_code $allowed_country { default $allowed_ip; DE yes; # Germany } log_format geoip '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent' '"$http_referer" $host "$http_user_agent"' '"$request_time" "$upstream_connect_time"' '"$geoip2_data_country_iso_code" "$allowed_country"'; ```
Author
Owner

@maboxx commented on GitHub (May 2, 2025):

One more question.... @cruunnerr
How did you implement the update of the Let's Encrypt certificates in the Nginx Proxy Manager? Pretty sure I have blocked the country from where the updates are coming from. I think I have to take the acme challenge out of the blocking so that it works.

<!-- gh-comment-id:2847895865 --> @maboxx commented on GitHub (May 2, 2025): One more question.... @cruunnerr How did you implement the update of the Let's Encrypt certificates in the Nginx Proxy Manager? Pretty sure I have blocked the country from where the updates are coming from. I think I have to take the acme challenge out of the blocking so that it works.
Author
Owner

@adamoutler commented on GitHub (May 2, 2025):

You blocked USA @maboxx ?

<!-- gh-comment-id:2848130466 --> @adamoutler commented on GitHub (May 2, 2025): You blocked USA @maboxx ?
Author
Owner

@cruunnerr commented on GitHub (May 3, 2025):

How did you implement the update of the Let's Encrypt certificates in the Nginx Proxy Manager?

I have an own domain with a wildcard certificate. So no need for me to use Let‘s encrypt. :/

<!-- gh-comment-id:2848413455 --> @cruunnerr commented on GitHub (May 3, 2025): > How did you implement the update of the Let's Encrypt certificates in the Nginx Proxy Manager? I have an own domain with a wildcard certificate. So no need for me to use Let‘s encrypt. :/
Author
Owner

@maboxx commented on GitHub (May 3, 2025):

You blocked USA @maboxx ?

Yes, I am currently only alowing my home country.

How did you implement the update of the Let's Encrypt certificates in the Nginx Proxy Manager?

I have an own domain with a wildcard certificate. So no need for me to use Let‘s encrypt. :/

I also have my own domain but at the moment I use the NPM function with Let's Encrypt because the certificates are always renewed automatically. You then always do this “manually” or via another automatic process?

<!-- gh-comment-id:2848558822 --> @maboxx commented on GitHub (May 3, 2025): > You blocked USA [@maboxx](https://github.com/maboxx) ? Yes, I am currently only alowing my home country. > > How did you implement the update of the Let's Encrypt certificates in the Nginx Proxy Manager? > > I have an own domain with a wildcard certificate. So no need for me to use Let‘s encrypt. :/ I also have my own domain but at the moment I use the NPM function with Let's Encrypt because the certificates are always renewed automatically. You then always do this “manually” or via another automatic process?
Author
Owner

@maboxx commented on GitHub (May 17, 2025):

I have now solved it so that the ACME Challenge continues to work.

The necessary allow exception for the ACME challenge is already in /etc/nginx/conf.d/include/letsencrypt-acme-challenge.conf by default and this is included in proxy_host.conf:

include conf.d/include/letsencrypt-acme-challenge.conf;

I have set this in the “Advanced” tab due to the previous discussions about the Web Gui:

if ($allowed_country = no) {
return 444;
}

However, this is then inserted too early in the proxy_host.conf and at the end it does not work. This part must be within the “location” block.

I have not yet found out how to do this via a custom.conf so that it ends up inside the location block. Therefore I have added each proxy host directly into the .conf. I don't have many so that's ok for me.

The allowed_country code must be added to the location block in the respective proxy_host.conf.

location / {
add_header Strict-Transport-Security $hsts_header always;

if ($allowed_country = no) {
    return 444;
}

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;

# Proxy!
include conf.d/include/proxy.conf;

}

Now it works. I have now only allowed my home country and the ACME Challenge from NPM still works.

<!-- gh-comment-id:2888251647 --> @maboxx commented on GitHub (May 17, 2025): I have now solved it so that the ACME Challenge continues to work. The necessary allow exception for the ACME challenge is already in /etc/nginx/conf.d/include/letsencrypt-acme-challenge.conf by default and this is included in proxy_host.conf: > include conf.d/include/letsencrypt-acme-challenge.conf; I have set this in the “Advanced” tab due to the previous discussions about the Web Gui: > if ($allowed_country = no) { > return 444; > } However, this is then inserted too early in the proxy_host.conf and at the end it does not work. This part must be within the “location” block. I have not yet found out how to do this via a custom.conf so that it ends up inside the location block. Therefore I have added each proxy host directly into the .conf. I don't have many so that's ok for me. The allowed_country code must be added to the location block in the respective proxy_host.conf. > location / { > add_header Strict-Transport-Security $hsts_header always; > > if ($allowed_country = no) { > return 444; > } > > proxy_set_header Upgrade $http_upgrade; > proxy_set_header Connection $http_connection; > proxy_http_version 1.1; > > # Proxy! > include conf.d/include/proxy.conf; > } Now it works. I have now only allowed my home country and the ACME Challenge from NPM still works.
Author
Owner

@terrytangabc commented on GitHub (May 26, 2025):

for anyone who's looking for a complete guide to enable geoip module in NPM, here are the steps:
before we start, check the volume your NPM container can access in the compose.yml file. We'll put all the file in this guide under here. For me it's

volumes:
  - /opt/docker/nginx-proxy-manager/data:/data

step 1: download GeoLite2-Country.mmdb
you can download directly from some Github repo which does not require sign-up or login. I download from here. Then save it to /opt/docker/nginx-proxy-manager/data/geoip2db/

step2: create /opt/docker/nginx-proxy-manager/data/nginx/custom/root_top.conf (create 'custom' dir if there is none)

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;

step3: create /opt/docker/nginx-proxy-manager/data/nginx/custom/http_top.conf. remember to modify the allowed_country code to your needs

# fix Nginx error
proxy_headers_hash_max_size 1024;
proxy_headers_hash_bucket_size 128;

geoip2 /data/geoip2db/GeoLite2-Country.mmdb {
    auto_reload 5m;
    $geoip2_data_country_iso_code country iso_code;
}

map $geoip2_data_country_iso_code $allowed_country {
    default no;
    DE yes; # set the allowed_country code to your needs
}

# Define private IP ranges (LAN IPs)
geo $lan_ip {
    default no;
    10.0.0.0/8 yes;
    172.16.0.0/12 yes;
    192.168.0.0/16 yes;
    127.0.0.1 yes;
}

log_format geoip '[$time_local] $upstream_cache_status $upstream_status $status - $request_method $scheme $host "$request_uri" [Client $remote_addr] [Length $body_bytes_sent] [Gzip $gzip_ratio] [Sent-to $server] "$http_user_agent" "$http_referer"'
	"$geoip2_data_country_iso_code" "$allowed_country";

step4: create /opt/docker/nginx-proxy-manager/data/nginx/custom/server_proxy.conf

# allow LAN
if ($lan_ip = yes) {
    set $allowed_country yes;
}
if ($allowed_country = no) {
    return 444;
}
# override NPM default access_log conf
access_log /data/logs/geoip.log geoip;

step5: restart your NPM container

! LIMITATIONS:
Default log format of NPM will be overridden.Tools rely on NPM logs might break(fail2ban, go access for NPM, etc.). Adjust the parameters in these tools accordingly after steps above applied. I didn't find a way to achieve this without overriding the log format.

<!-- gh-comment-id:2908450703 --> @terrytangabc commented on GitHub (May 26, 2025): for anyone who's looking for a complete guide to enable geoip module in NPM, here are the steps: before we start, check the volume your NPM container can access in the compose.yml file. We'll put all the file in this guide under here. For me it's ``` volumes: - /opt/docker/nginx-proxy-manager/data:/data ``` step 1: download GeoLite2-Country.mmdb you can download directly from some Github repo which does not require sign-up or login. I download from [here](https://github.com/PrxyHunter/GeoLite2/releases/tag/2024.10.19). Then save it to `/opt/docker/nginx-proxy-manager/data/geoip2db/` step2: create /opt/docker/nginx-proxy-manager/data/nginx/custom/root_top.conf (create 'custom' dir if there is none) ``` load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so; ``` step3: create /opt/docker/nginx-proxy-manager/data/nginx/custom/http_top.conf. remember to modify the allowed_country code to your needs ``` # fix Nginx error proxy_headers_hash_max_size 1024; proxy_headers_hash_bucket_size 128; geoip2 /data/geoip2db/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_data_country_iso_code country iso_code; } map $geoip2_data_country_iso_code $allowed_country { default no; DE yes; # set the allowed_country code to your needs } # Define private IP ranges (LAN IPs) geo $lan_ip { default no; 10.0.0.0/8 yes; 172.16.0.0/12 yes; 192.168.0.0/16 yes; 127.0.0.1 yes; } log_format geoip '[$time_local] $upstream_cache_status $upstream_status $status - $request_method $scheme $host "$request_uri" [Client $remote_addr] [Length $body_bytes_sent] [Gzip $gzip_ratio] [Sent-to $server] "$http_user_agent" "$http_referer"' "$geoip2_data_country_iso_code" "$allowed_country"; ``` step4: create /opt/docker/nginx-proxy-manager/data/nginx/custom/server_proxy.conf ``` # allow LAN if ($lan_ip = yes) { set $allowed_country yes; } if ($allowed_country = no) { return 444; } # override NPM default access_log conf access_log /data/logs/geoip.log geoip; ``` step5: restart your NPM container ! LIMITATIONS: Default log format of NPM will be overridden.Tools rely on NPM logs might break(fail2ban, go access for NPM, etc.). Adjust the parameters in these tools accordingly after steps above applied. I didn't find a way to achieve this without overriding the log format.
Author
Owner

@adamoutler commented on GitHub (May 26, 2025):

@terrytangabc you should contribute to the docs. They're very unclear and anything would be better.

<!-- gh-comment-id:2909245014 --> @adamoutler commented on GitHub (May 26, 2025): @terrytangabc you should contribute to the docs. They're very unclear and anything would be better.
Author
Owner

@bonelifer commented on GitHub (Jun 18, 2025):

I had a go at adding @terrytangabc section into the documentation. Don't know anything about vitepress, I used Deepseek to bring the directions more in line with the same document style/tone as the rest of the Advanced Configuration (index.md). If someone could look it over to make sure nothing was left out. I'll fork and add it and do a PR.

edit: it would help if I put the URL for the gist: https://gist.github.com/bonelifer/765fdfce1af0df2a57fed4e62c7bdaf4

<!-- gh-comment-id:2985389088 --> @bonelifer commented on GitHub (Jun 18, 2025): I had a go at adding @terrytangabc section into the documentation. Don't know anything about vitepress, I used Deepseek to bring the directions more in line with the same document style/tone as the rest of the Advanced Configuration (index.md). If someone could look it over to make sure nothing was left out. I'll fork and add it and do a PR. edit: it would help if I put the URL for the gist: https://gist.github.com/bonelifer/765fdfce1af0df2a57fed4e62c7bdaf4
Author
Owner

@uniquegch commented on GitHub (Jul 8, 2025):

@terrytangabc Thank you for the instructions.
I do have two questions.

  1. within http_top.conf I can add countries I allow, do I add them one line each or in the same line?
    for example:
    DE yes;
    NL yes;
    or DE NL yes;

  2. I have goaccess for NPM installed and see hits from Australia, Sweden, US, etc but based on the allowed countries that should not be the case.
    examples (frist number seems to be ASN for which I do not ave the database integrated):

  • 204957: Green Floid LLC
  • 39351: 31173 Services AB
  • 14061: DIGITALOCEAN-ASN
  • 18345: Servers Australia Customers
  • 16509: AMAZON-02
  • 4286: LOGICWEB

I know that ACME is already allowed, so could that be the sources not being blocked by "allowed countries"?
and one more thing. The nginxproxymanager and goaccess for nginxproxymanager is running brand new since today.

<!-- gh-comment-id:3048907476 --> @uniquegch commented on GitHub (Jul 8, 2025): @terrytangabc Thank you for the instructions. I do have two questions. 1. within http_top.conf I can add countries I allow, do I add them one line each or in the same line? for example: DE yes; NL yes; or DE NL yes; 2. I have goaccess for NPM installed and see hits from Australia, Sweden, US, etc but based on the allowed countries that should not be the case. examples (frist number seems to be ASN for which I do not ave the database integrated): - 204957: Green Floid LLC - 39351: 31173 Services AB - 14061: DIGITALOCEAN-ASN - 18345: Servers Australia Customers - 16509: AMAZON-02 - 4286: LOGICWEB I know that ACME is already allowed, so could that be the sources not being blocked by "allowed countries"? and one more thing. The nginxproxymanager and goaccess for nginxproxymanager is running brand new since today.
Author
Owner

@terrytangabc commented on GitHub (Jul 9, 2025):

@uniquegch

  1. One per line
  2. You should check your NPM access logs to see if 'disallowed countries' are blocked(HTTP status 444). Blocked requests will still be logged by Nginx. So goaccess for NPM will still find requests from blocked countries when it walks through the logs. And don't forget to adjust the 'LOG FORMAT' param in go access for NPM since it can only understand the default log format of NPM but we override the log format in step 3 above.
<!-- gh-comment-id:3050888757 --> @terrytangabc commented on GitHub (Jul 9, 2025): @uniquegch 1. One per line 2. You should check your NPM access logs to see if 'disallowed countries' are blocked(HTTP status 444). Blocked requests will still be logged by Nginx. So goaccess for NPM will still find requests from blocked countries when it walks through the logs. And don't forget to adjust the 'LOG FORMAT' param in go access for NPM since it can only understand the default log format of NPM but we override the log format in step 3 above.
Author
Owner

@uniquegch commented on GitHub (Jul 9, 2025):

@terrytangabc Thank you for your reply.

I do know enough to be "dangerous", but that is already a new area for me to learn more about.
A. I looked in npm/data/logs and there was no geoip but in the server_proxy.conf I put in the information I found in the instructions step 4
# override NPM default access_log conf
access_log /data/logs/geoip.log geoip

B. I also wondering about the step 2 creating the file root_top.conf and the two lines

load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;

Because I assume those would be within the npm docker container? within the server (debian 12) I do not have those files under /usr/lib/

C. goaccess for nginxproxymanager finds two of several logs

File /opt/log/proxy-host-2_access.log exists
File /opt/log/proxy-host-1_access.log exists

there are also two proxy-host-N_error.log files

<!-- gh-comment-id:3051480531 --> @uniquegch commented on GitHub (Jul 9, 2025): @terrytangabc Thank you for your reply. I do know enough to be "dangerous", but that is already a new area for me to learn more about. A. I looked in npm/data/logs and there was no geoip but in the server_proxy.conf I put in the information I found in the instructions **step 4** _# override NPM default access_log conf access_log /data/logs/geoip.log geoip_ B. I also wondering about the step 2 creating the file root_top.conf and the two lines _load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;_ Because I assume those would be within the npm docker container? within the server (debian 12) I do not have those files under /usr/lib/ C. goaccess for nginxproxymanager finds two of several logs _File /opt/log/proxy-host-2_access.log exists File /opt/log/proxy-host-1_access.log exists_ there are also two proxy-host-N_error.log files
Author
Owner

@uniquegch commented on GitHub (Jul 10, 2025):

I had fix the path. now it is working and I tested the geo lock which works. Now I have to find out how to change the settings in goaccess for getting the log in the correct format.
Thanks for the instructions.

<!-- gh-comment-id:3059017249 --> @uniquegch commented on GitHub (Jul 10, 2025): I had fix the path. now it is working and I tested the geo lock which works. Now I have to find out how to change the settings in goaccess for getting the log in the correct format. Thanks for the instructions.
Author
Owner

@BourbonDoc commented on GitHub (Sep 3, 2025):

I've tried a few versions of these steps and it still doesn't work. I get the error that no such file exists for the module.so files. I haven't seen anywhere that talks about creation of a modules folder or what files to put in it. Am I missing something really dumb?

<!-- gh-comment-id:3250676740 --> @BourbonDoc commented on GitHub (Sep 3, 2025): I've tried a few versions of these steps and it still doesn't work. I get the error that no such file exists for the module.so files. I haven't seen anywhere that talks about creation of a modules folder or what files to put in it. Am I missing something really dumb?
Author
Owner

@zigazajc007 commented on GitHub (Sep 8, 2025):

Is it possible for this to be implemented in the dashboard?

Example we just select whitelisted and blocked countries. And set if default is allow all or deny all countries.

<!-- gh-comment-id:3267787539 --> @zigazajc007 commented on GitHub (Sep 8, 2025): Is it possible for this to be implemented in the dashboard? Example we just select whitelisted and blocked countries. And set if default is allow all or deny all countries.
Author
Owner

@nbently commented on GitHub (Oct 8, 2025):

Is it possible for this to be implemented in the dashboard?

Example we just select whitelisted and blocked countries. And set if default is allow all or deny all countries.

This would definitely be ideal. I had planned on taking a stab at this but life is busy. There are really two separate PRs here. The first is just adding functionality to allow requests to be tagged with the location in the logs using the GeoIP module and the second is functionality to block requests based on location.

When I originally built this into NPM, it was only with the intention of being able to visualize where requests were coming from and not to block them, so more thought needs to go into that.

I'll think more about this and see if I can find some time to at least postulate how the first PR could be structured.

<!-- gh-comment-id:3383568451 --> @nbently commented on GitHub (Oct 8, 2025): > Is it possible for this to be implemented in the dashboard? > > Example we just select whitelisted and blocked countries. And set if default is allow all or deny all countries. This would definitely be ideal. I had planned on taking a stab at this but life is busy. There are really two separate PRs here. The first is just adding functionality to allow requests to be tagged with the location in the logs using the GeoIP module and the second is functionality to block requests based on location. When I originally built this into NPM, it was only with the intention of being able to visualize where requests were coming from and not to block them, so more thought needs to go into that. I'll think more about this and see if I can find some time to at least postulate how the first PR could be structured.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-proxy-manager-NginxProxyManager#45
No description provided.