-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GeoIP module #46
Comments
Sounds doable. Makes sense to include with improvements in #38 as well. |
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. 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 ? |
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. |
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 |
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. |
This comment has been minimized.
This comment has been minimized.
This would be awesome because in order to use this Currently nginx fails with this error when I add the custom log format:
I need the geoIP information to send to InfluxDB custom format:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Likewise this will help massively in reducing attempted logons and bruteforcing on my network. Watching closely. |
Hi guys, |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
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. |
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! |
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! |
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. |
Here some useful material to compile geoip2 in openresty |
Did this get progressed any? Or is it waiting for someone to pick it up? |
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. |
I've actually made my own custom version of it with geoIP in order to use it with loki and grafana. 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 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. |
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. |
Thank you for the link but |
@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. |
@nbently
I have now started Docker. How can I now check whether the module is loaded or working? |
@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). |
I am sad, there is no log :-(
I don't understand it. I do exactly what you do. |
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
I changed the DatabaseDirectory in /etc/GeoIP.conf: First try to download database: Then created a crontab for updating database.
Then I created the files NPM_DOCKER_FOLDER/modules/enable_ngx_http_geoip2_module.conf My files look like this: enable_ngx_http_geoip2_module.conf: http_top.conf:
server_proxy.conf:
Then I added the volume mounts to the docker-compose.yml:
start the container:
Notice that I added the
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. :) |
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. Just think about it ;) |
@maboxx can you show us where you have the bind mounts configured? |
I probably won't have time to go through the whole thing again until the weekend. @nbently
|
@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. |
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? @cruunnerr |
Great Alternative. |
@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. |
I think this issue is fixed on #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. |
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 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;
} |
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:
Never keep just one layer of security. |
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. |
Hi there, i also tried the comment as per @phyte22 here #46 (comment) , and setup everything according to the same volume mounts. The
My proxy host goes
When I then go to The
The |
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. |
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
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
is added then an error like
is returned. If conditionals/if cannot be used there, how the same as proxy hosts can be achieved? 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
Then
this allows httpS traffic for the proxy hosts. Then:
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:
The first one is necessary also to allow reach the NPM GUI with the host IP on port 81. |
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
server_proxy.conf
|
@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. |
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 think is because the first line of http_top.conf
but where is the database of geoip2 with this config? |
I think i understand something (let me know if is true).
Now i'm stuck in the next step that i read more up in #46 (comment) After you can create map on server block:
... where i must put this? EDIT: i add the block in http_top.conf |
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!
The text was updated successfully, but these errors were encountered: