Loading
0

如何只允许某一个ip或某几个ip访问网站?

若该文章解决了您的问题,可否收藏+评论+分享呢?
前言:生成环境中很多时候不想其他人访问网站,只需要特定的几个ip访问,这种情况可参考如下处理方法:
将如下代码中的ip更换为您自己允许的ip即可。
web.config规则(支持iis7/iis8/iis10)
允许单个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}&amp;%{REMOTE_ADDR}&amp;%{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后面不加竖线

<?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}&amp;%{REMOTE_ADDR}&amp;%{HTTP_X_Real_IP}" pattern="(118.118.118.118|123.123.123.123|12.12.12.12)" 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>


 

声明:站长码字很辛苦啊,转载时请保留本声明及附带文章链接:https://blog.tag.gg/showinfo-39-36103-0.html
亲爱的:若该文章解决了您的问题,可否收藏+评论+分享呢?
上一篇:网站域名被移动网络屏蔽了怎么办?
下一篇:网站被黑怎么办?怎么预防?做好如下几点。