mirror of
https://github.com/idanoo/m2.nz.git
synced 2024-11-22 16:25:13 +00:00
Update geoip
This commit is contained in:
parent
1189975161
commit
790fa31ba5
@ -1,23 +1,20 @@
|
|||||||
---
|
---
|
||||||
title: "Geo Blocking countries with nginx"
|
title: "GeoIP blocking countries using nginx"
|
||||||
tags: ["spam", "geo block", "nginx"]
|
tags: ["nginx", "geoip", "spam", "geo block"]
|
||||||
date: "2024-04-07"
|
date: "2024-04-06"
|
||||||
---
|
---
|
||||||
|
|
||||||
Quick and easy way to block entire countries using simple nginx rules.
|
Quick and easy way to block entire countries using simple nginx rules.
|
||||||
Note this is primarily for Ubuntu/Nginx but may work on other systems
|
Note this is for Ubuntu/Nginx but may work on other systems.
|
||||||
|
|
||||||
Install required fields
|
Install required packages & add to nginx config.
|
||||||
|
The GeoIP DB will be under /usr/shared/GeoIP/GeoIPv6.dat (Or GeoIP.dat for v4 only):
|
||||||
```shell
|
```shell
|
||||||
apt install -y libnginx-mod-http-geoip geoip-database
|
apt install -y libnginx-mod-http-geoip geoip-database
|
||||||
```
|
|
||||||
|
|
||||||
The GeoIP DB will be under /usr/shared/GeoIP/GeoIPv6.dat (Or GeoIP.dat for v4 only)
|
|
||||||
We need to add this into nginx conf:
|
|
||||||
```shell
|
|
||||||
echo 'geoip_country /usr/share/GeoIP/GeoIP.dat;' > /etc/nginx/conf.d/geoip.conf
|
echo 'geoip_country /usr/share/GeoIP/GeoIP.dat;' > /etc/nginx/conf.d/geoip.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Add this block under the main "http" block in nginx.conf:
|
Add this block under the main "http" block in nginx.conf:
|
||||||
```shell
|
```shell
|
||||||
# /etc/nginx/nginx.conf
|
# /etc/nginx/nginx.conf
|
||||||
@ -27,7 +24,7 @@ map $geoip_country_code $allowed_country {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Then we need to add a simple check in our site vhost:
|
Then we need to add a simple check in our site vhost inside the `server {` block, but before the `location /` block:
|
||||||
```shell
|
```shell
|
||||||
# /etc/nginx/sites-enabled/your_site.conf
|
# /etc/nginx/sites-enabled/your_site.conf
|
||||||
if ($allowed_country = no) {
|
if ($allowed_country = no) {
|
||||||
|
Loading…
Reference in New Issue
Block a user