云服务器

首页 > 虚拟主机 > linux系统和windows系统虚拟主机屏蔽ip访问的方法

linux系统和windows系统虚拟主机屏蔽ip访问的方法

注:
如果只屏蔽IP 8.8.4.4 则写(8.8.4.4)
如果只屏蔽IP段8.8.8.* 则写(8.8.8\.)
屏蔽多段中间用|隔开,如(8.8.4.4|8.8.8\.)

Linux虚拟主机规则文件.htaccess(手工创建.htaccess文件到站点根目录)

<IfModule mod_rewrite.c>
RewriteEngine On
#Block ip
RewriteCond %{http:X-Forwarded-For} ^(8.8.4.4|8.8.8\.) [OR]
RewriteCond %{REMOTE_ADDR} ^(8.8.4.4|8.8.8\.) [OR]
RewriteCond %{http:X-Real-IP} ^(8.8.4.4|8.8.8\.) [NC]
RewriteRule (.*) - [F]
</IfModule>

windows平台IIS7及以上版本 规则文件web.config (手工创建web.config文件到虚拟主机站点根目录)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>   
        <rewrite>
            <rules>               
                <rule name="band ip">
                    <match url="(.*)" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny"> 
                        <add input="{HTTP_X_FORWARDED_FOR}" pattern="^(8.8.4.4|8.8.8\.)" ignoreCase="false" />
                        <add input="{REMOTE_ADDR}" pattern="^(8.8.4.4|8.8.8\.)" ignoreCase="false" />
                        <add input="{HTTP_X_REAL_IP}" pattern="^(8.8.4.4|8.8.8\.)" ignoreCase="false" />                      
                    </conditions>
                <action type="AbortRequest" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>  
</configuration>

nginx宝塔面板设置屏蔽IP规则,可以在宝塔面板-》对应站点伪静态处设置:

if ( $http_x_forwarded_for ~* ‘8.8.8.8|114.114.114.114’) 

{return 444;}

if ( $remote_addr  ~* ‘8.8.8.8|114.114.114.114’) 

{return 444;}

if ( $http_x_real_ip  ~* ‘8.8.8.8|114.114.114.114’) 

{return 444;}

图片描述

发表回复