apache, iis6, ii7 dedicated IP host blocking/restricting IP access (applicable to VPS cloud hosting)
Published: 2014-12-25
Note:
If blocking only IP 8.8.4.4, write (8.8.4.4)
If blocking only IP range 8.8.8.*, write (8.8.8\.)
To block multiple ranges, separate them with |, e.g. (8.8.4.4|8.8.8\.)
Rule file .htaccess under Linux (manually create the .htaccess file in the site root directory)
<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>Rule file httpd.conf under windows2003
If our company's assistant environment is installed, please first followhttp://www.west.cn/faq/list.asp?unid=650 to enable the pseudo-static component, then add the following rules.
If it is a clean version system, please followhttp://www.west.cn/faq/list.asp?unid=639 to enable the pseudo-static component, then configure according to the following system rules in the configuration file
#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]Rule file web.config for Windows platform IIS7 and above (manually create the web.config file in the site root directory)
<?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>To set IP blocking rules in nginx 宝塔面板, you can set them in 宝塔面板 -> the corresponding site's pseudo-static section:
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;}
