Closed richzhu369 closed 1 month ago
http {
geoip_country /path/to/GeoIP/GeoIP.dat;
server {
listen 80;
server_name your_domain.com;
location / {
# 检查访问者国家,只允许中国(CN)访问和特定 IP 地址(1.1.1.1)
if ($geoip_country_code != CN) {
if ($remote_addr != 18.163.177.7) {
return 403;
}
}
# 其他配置
}
}
}
本项目中的 dat 格式 geoip 文件是 V2Ray 专属的,不能用于 Nginx。
Nginx 中的 dat 格式 geoip 数据库来源于 MaxMind,但这个格式已经被 MaxMind 列为过时,MaxMind 现在推荐使用 mmdb 格式。本项目中的 mmdb 格式文件理论上可用于 Nginx,但我没有尝试过,代码中只保留了一个变量 iso_code
(两位字母的国家代号) 。
在 Nginx 中使用 mmdb 格式 geoip 文件,可以参考:https://github.com/leev/ngx_http_geoip2_module
另外,对于 IP / CIDR 的简单访问控制,也可以使用 Nginx 的 allow
和 deny
,参考:https://github.com/Loyalsoldier/geoip/tree/release/nginx
请问nginx能用吗,我想用来判断国家