AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1054440
Accepted
Carol.Kar
Carol.Kar
Asked: 2021-02-21 14:19:46 +0800 CST2021-02-21 14:19:46 +0800 CST 2021-02-21 14:19:46 +0800 CST

只有某些国家可以访问特定路线

  • 772

我nginx/1.18.0 (Ubuntu)在Ubuntu 20.04.1 LTS机器上使用。

我有一个laravel project和phpmyadmin运行。

我的/etc/nginx/sites-enabled/example-application文件如下所示:

server {
    listen 80;
    server_name http://78.46.214.238/;
    root /var/www/demo_laravel_nlg-generation/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    # phpMyAdmin:
    location /phpmyadmin {
        root /usr/share;
        index index.php;
    }
    # PHP files for phpMyAdmin:
    location ~ ^/phpmyadmin(.+\.php)$ {
        root /usr/share;
        index index.php;
        #fastcgi_read_timeout 300;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

}

为了保护我的 web phpmyadmin 界面,我想阻止某些国家甚至地区,或者只允许特定 IP 访问我的\phpmyadmin路由,但是我的 web 应用程序仍然应该可供所有人访问。

任何建议如何在我的/etc/nginx/sites-enabled/example-application文件中执行此操作?

我真的很感谢你的回复!

nginx phpmyadmin
  • 1 1 个回答
  • 106 Views

1 个回答

  • Voted
  1. Best Answer
    Muhammad Dyas Yaskur
    2021-02-21T15:05:54+08:002021-02-21T15:05:54+08:00

    要允许只需将其添加到您的/etc/nginx/sites-enabled/example-application

    allow   allowed.public.ip.here;
    deny    all;
    

    allowed.public.ip.here可以更改为 IP(示例1.1.1.1)或子网 IP 类(1.1.0.0/16阻止 IP 范围从 1.1.0.0 到 1.1.255.255 的示例)。一个例子:

    location ~ ^/phpmyadmin(.+\.php)$ {
        allow   1.1.0.0/16;
        deny    all;
        root /usr/share;
        index index.php;
        #fastcgi_read_timeout 300;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }
    

    要阻止某些国家/地区,您需要GeoIp 模块。但我不推荐它,因为它会影响低规格服务器的性能。但是,如果您只想使用以下命令在 Ubuntu 上安装 Geo IP DB;

    apt-get install geoip-database libgeoip1 
    

    然后将其添加到您的配置中:

    geoip_country /usr/share/GeoIP/GeoIP.dat;
    map $geoip_country_code $allow_visit {
       default yes;
       US no;
       CA no;
    }
    

    上面的例子是阻止美国和加拿大。

    要阻止区域/大陆,您可以使用新的 GeoIP 数据库,您可以按照以下步骤操作,但我尚未对其进行测试

    • 1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve