• nginx应用geoip模块,实现不同地区访问不同页面的需求(实践版)


    https://www.52os.net/articles/configure-nginx-using-geoip-allow-whitelist.html       搞了几天没有搞定,这篇文章一下子解决了问题,点赞

     记得nginx编译时一定要加载geoip这个模块

     https://blog.csdn.net/beyond__devil/article/details/52838422   地区代码表

    主配置文件geoip模块的配置如下:


    geoip_country /usr/local/nginx/conf/GeoIP/GeoIP.dat;
    geoip_city /usr/local/nginx/conf/GeoIP/GeoLiteCity.dat;
    geo $remote_addr $ip_whitelist {
    default 0;
    include ip.conf;
    }
    map $geoip_city $allow_city {
    default no;
    Jinhua yes;
    #Beijing yes;
    Shanghai yes;
    Guangzhou yes;
    Chongqing yes;
    Shandong yes;
    }

    我的vhost目录下的a.conf配置如下

    server {
    listen 80;
    server_name jiaji.com;
    access_log /home/nginx/beijing.log;

    location / {
    root /var/www/web/ABBEIJING/xiqing;
    index index.html index.htm index.php;

    if ( $geoip_region = "22" ) {       ##这里的22是北京地区
    root /var/www/web/ABBEIJING/laohushenhe;
    }

    if ($allow_city = yes) {
    root /var/www/web/ABBEIJING/xiqing;
    }

    }
    }

    另一个运用geoip的站点,需求:默认访问/var/www/web/hongb目录,北上广深重庆访问/var/www/web/zhi目录,在允许城市列表(nginx.conf文件里指定的允许城市列表)的城市也是访问/var/www/web/hongb目录

    server {
    listen 80;
    server_name hongb.com;

    location / {
    root /var/www/web/hongb;
    index index.html index.htm index.php;

    if ( $geoip_region = "22" ) { ##这里的22是北京地区
    root /var/www/web/zhi;
    }

    if ( $geoip_region = "23" ) { ##这里的23是上海地区
    root /var/www/web/jzhi;
    }

    if ( $geoip_region = "30" ) { ##这里的30是广东地区
    root /var/www/web/jzhi;
    }

    if ( $geoip_region = "32" ) { ##这里的32是四川地区
    root /var/www/web/jzhi;
    }

    if ($allow_city = yes) {
    root /var/www/web/hongb;
    }
    }
    }

  • 相关阅读:
    四则运算网页版
    第六周工作日志
    课堂作业数组最大和
    第五周总结
    四则运算三结对开发
    学习进度第四周
    个人模块记录表
    学习进度表第三周
    四则运算第二篇
    保序回归问题
  • 原文地址:https://www.cnblogs.com/leon2659/p/9534053.html
Copyright © 2020-2023  润新知