Giter Site home page Giter Site logo

请问nginx能用吗 about geoip HOT 2 CLOSED

richzhu369 avatar richzhu369 commented on August 26, 2024
请问nginx能用吗

from geoip.

Comments (2)

richzhu369 avatar richzhu369 commented on August 26, 2024
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;
                }
            }

            # 其他配置
        }
    }
}

from geoip.

Loyalsoldier avatar Loyalsoldier commented on August 26, 2024

本项目中的 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 的 allowdeny,参考:https://github.com/Loyalsoldier/geoip/tree/release/nginx

from geoip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.