将如下代码中的ip更换为您自己允许的ip即可。
web.config规则(支持iis7/iis8/iis10)
只允许单个ip访问站点:(请将118.118.118.118更换为您允许访问的ip)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="band ip" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="%{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP}" pattern="(118.118.118.118)" ignoreCase="false" negate="true" />
</conditions>
<action type="AbortRequest" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
允许多个ip或某个ip段访问:(注意ip间用竖线分隔,最后一个ip后面不加竖线 可以填写ip段,比如 114.114.114. 表示这个c段,注意后面有一个点号)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="band ip" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="%{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP}" pattern="(118.118.118.118|123.123.123.123|12.12.12.12|125.70.35.)" ignoreCase="false" negate="true" />
</conditions>
<action type="AbortRequest" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Aapche允许单个ip访问:
<IfModule mod_rewrite.c>
RewriteEngine On
#Block ip
RewriteCond %{http:X-Forwarded-For}&%{REMOTE_ADDR}&%{http:X-Real-IP} !^(123.123.132.123)
RewriteRule (.*) - [F]
</IfModule>
Aapche允许多个ip访问:(注意ip间用竖线分隔,最后一个ip后面不加竖线)
<IfModule mod_rewrite.c>
RewriteEngine On
#Block ip
RewriteCond %{http:X-Forwarded-For}&%{REMOTE_ADDR}&%{http:X-Real-IP} !^(123.123.132.123|12.12.12.12)
RewriteRule (.*) - [F]
</IfModule>
文章评论 本文章有个评论