WINDOWS系统云虚拟主机及驰云产品访问IP限制方法
使用新网Windows系统云虚拟主机和驰云主机的客户,如需要限制某些IP访问,或只允许某些IP访问,可以通过如下方式实现。
1. 限制部分IP访问:
请自行创建并编写web.config文件,上传至网站根目录下的/WWW/目录中。
内容如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" /> <conditions logicalGrouping="MatchAny"> <add input="{REMOTE_ADDR}" pattern="192.168.0.1" /> <add input="{REMOTE_ADDR}" pattern="192.168.1.*" /> </conditions> <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." /> </rule> </rules> </rewrite> </system.webServer> </configuration> |
RequestBlockingRule1 限制了192.168.0.1单个IP访问及192.168.1.* 整个C段访问。
2. 只允许部分IP访问
请自行创建并编写web.config文件,上传至网站根目录下的/WWW/目录中。
内容如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" /> <conditions> <add input="{REMOTE_ADDR}" pattern="192.168.0.1" negate="true" /> <add input="{REMOTE_ADDR}" pattern="192.168.1.*" negate="true" /> </conditions> <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." /> </rule> </rules> </rewrite> </system.webServer> </configuration> |
RequestBlockingRule1 只允许192.168.0.1单个IP访问及192.168.1.* 整个C段访问。
说明:
通过URL重写功能,可以实现基于URL路径、用户代理标头、IP地址、查询字符串、引用站点、主机头的限制,满足对网站的保护,新网新虚拟主机及驰云主机支持网站自定制的URL重写功能。
如需要更复杂限制策略,请在本地IIS7以上版本安装URL重写模块进行调试后上传。