找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
楼主: a276229381

通过CLOUDFLARE屏蔽国家代码。

[复制链接]

11

主题

437

回帖

983

积分

高级会员

积分
983
发表于 2016-11-6 23:02:34 | 显示全部楼层
javascript 的比较好用

[script type="text/javascript"]
$(document).ready(function () {
jQuery.ajax({
url: 'http://freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function (location) {
if (location.country_code == '国家代码比如VN') {
window.top.location.href = '自定义禁止页面';
}
}
});
});
[/script]
回复

使用道具 举报

120

主题

306

回帖

1042

积分

金牌会员

积分
1042
 楼主| 发表于 2016-11-6 23:06:29 | 显示全部楼层

ANYMOZ 发表于 2016-11-7 00:01

javascript 的比较好用

[script type="text/javascript"]

这个是放在NGINX的配置文件吗?还是在HTML页面调用这个JS?
回复

使用道具 举报

120

主题

306

回帖

1042

积分

金牌会员

积分
1042
 楼主| 发表于 2016-11-6 22:59:00 | 显示全部楼层

ANYMOZ 发表于 2016-11-7 00:01

javascript 的比较好用

[script type="text/javascript"]

哦。。。谢谢。。有什么办法不让他访问吗  或者禁止。。这个方法网页是可以打开的。
回复

使用道具 举报

188

主题

4322

回帖

9318

积分

论坛元老

积分
9318
发表于 2016-11-6 23:47:59 | 显示全部楼层
本帖最后由 guyusoftware 于 2016-11-7 00:55 编辑

a276229381 发表于 2016-11-6 23:02

我是WDCP  我修改的  www/wdlinux/nginx/conf/vhost/www.123.com.conf


Note: You must retrieve the IP Geolocation information from the
CF-IPCountry
HTTP header.
文章裡的是 HTTP_CF_IPCOUNTRY
你在用教學的時候 也得看看是否一樣啊.............




現在:



以前:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

120

主题

306

回帖

1042

积分

金牌会员

积分
1042
 楼主| 发表于 2016-11-6 22:40:00 | 显示全部楼层

guyusoftware 发表于 2016-11-7 00:53

Note: You must retrieve the IP Geolocation information from the CF-IPCountry HTTP header.
文章裡的 ...

我把    map $http_cf_ipcountry $allow {   改为 cf_ipcountry  一样屏蔽不了哇。。大神
  
回复

使用道具 举报

485

主题

5467

回帖

1万

积分

论坛元老

积分
12547
发表于 2016-11-6 22:40:44 | 显示全部楼层
https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-CloudFlare-handle-HTTP-Request-headers-

[ol]
  • Fourth Exception: CF-IPCountry
  • This header holds the country code of the originating visitor, it is a two character value that will have the Country code, if the country code is unknown, it will be "XX".
  • "Cf-Ipcountry: US"[/ol]复制代码
  • 回复

    使用道具 举报

    12

    主题

    380

    回帖

    852

    积分

    高级会员

    积分
    852
    发表于 2016-11-7 00:01:47 | 显示全部楼层
    本帖最后由 DeepSkyFire 于 2016-11-7 01:41 编辑

    a276229381 发表于 2016-11-6 23:02

    我是WDCP  我修改的  www/wdlinux/nginx/conf/vhost/www.123.com.conf




            if ($http_cf-ipcountry ~* (CN|KP|VN|JP)){
            return 403;
            }

    你就别再问了,我之前已经给你过一个确定能用的PHP代码,你自己不用也不会去搜。所以你就别再问我这代码加哪里去了。我能做的就只能做到这了。拜拜。
    回复

    使用道具 举报

    120

    主题

    306

    回帖

    1042

    积分

    金牌会员

    积分
    1042
     楼主| 发表于 2016-11-7 00:24:05 | 显示全部楼层

    DeepSkyFire 发表于 2016-11-7 01:19

    if ($http_cf-ipcountry ~* (CN|KP|VN|JP)){
            return 403;
            }

    虽然不好意思。。但是我还是想问一下。。
    server {
            listen       80;
            root /www/web/123_com/public_html;
            server_name 123.com;
            index  index.html index.php index.htm;
            error_page  400 /errpage/400.html;
            error_page  403 /errpage/403.html;
            error_page  404 /errpage/4041.html;
            error_page  503 /errpage/503.html;
            location ~ \.php$ {
                    proxy_pass http://127.0.0.1:88;
                    include naproxy.conf;
            }
            location ~ /\.ht {
                    deny  all;
            }
            location / {
                    try_files $uri @apache;
            }
            location @apache {
                     proxy_pass http://127.0.0.1:88;
                     include naproxy.conf;
            }  

    if ($HTTP_CF-IPCountry ~* (CN|KP|VN|JP)){
            return 403;
            }   
          
             
    }


    加上去之后。。还是可以访问网站 根本无效啊。。你说的PHP代码 我测试过了 也搜了相关资料。快几个月了。没结果。。我肯定是搜了教程的。
    回复

    使用道具 举报

    135

    主题

    656

    回帖

    1791

    积分

    金牌会员

    积分
    1791
    发表于 2016-11-7 00:01:00 | 显示全部楼层

    DeepSkyFire 发表于 2016-11-7 01:19

    if ($http_cf-ipcountry ~* (CN|KP|VN|JP)){
            return 403;
            }

    是不是因为我用WDCP的关系。。

    error_page  404 /errpage/4041.html;

    我修改错误404指向到4041.html 但是他依然用原来的404.html  我修改之后重启过服务器了。还是不生效。
    a276229381 发表于 2016-11-7 01:50

    虽然不好意思。。但是我还是想问一下。。
    server {
            listen       80;

    正則式出問題了,抱歉。
    if ($http_cf_ipcountry = HK){
            return 403;
            }

    以上代碼親自測試能正確使用。需要屏蔽多個國家可以自己去研究下正則式。
    回复

    使用道具 举报

    236

    主题

    1297

    回帖

    3390

    积分

    论坛元老

    积分
    3390
    发表于 2016-11-7 00:47:57 | 显示全部楼层
    哈哈哈哈哈,围观255狂人
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-4-20 04:09 , Processed in 0.020794 second(s), 3 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表