当前位置 主页 > 服务器问题 > win服务器问题汇总 >

    win2008 IIS7.5防盗链配置方法

    栏目:win服务器问题汇总 时间:2019-03-06 09:28

    最近有客户配置了win2008 iis7.5,因为转载的比较多,所以考虑到简单的防盗链,特整理下方便需要的朋友

    1、下载微软自己提供的IIS REWRITE模块

    64位:
    http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=1b8c7bd8-8824-4408-b8fc-49dc7f951a00
    32位:
    http://www.microsoft.com/zh-cn/download/details.aspx?id=5747

    IIS7站长之家下载://www.iis7.com/softs/479310.html

    2、修改网站的web.config或用记事本制作一个web.config,记住将*txt格式改为.config 代码如下:

    <system.webServer> <rewrite> <rules> <rule name="Prevent hotlinking"> <match url="^.*\.(rar|zip|7z)$" ignoreCase="true" /> <conditions> <add input="{HTTP_REFERER}" pattern="//www.iis7.com/.*" negate="true" /> <add input="{HTTP_REFERER}" pattern="http://wt.jb51.net/.*" negate="true" /> </conditions> <action type="Rewrite" url="/no.html" /> </rule> </rules> </rewrite> </system.webServer> 

    设置了只允许//www.iis7.com、http://wt.jb51.net调用网站的rar、zip类型的文件。
    将以上文件上传至网站根目录(wwwroot)下即可 如果网站有设置伪静态,直接将上述代码加入原有web.config一样可以生效

    IIS7站长之家小编注:上面的内容需要放在<configuration>里面。例如如下是完整的

    <?xml version="1.0" encoding="UTF-8"?><configuration>  <system.webServer>    <staticContent>      <mimeMap fileExtension=".*" mimeType="appliction/force-download" />    </staticContent>    <httpErrors>      <remove statusCode="404" subStatusCode="-1" />      <error statusCode="404" prefixLanguageFilePath="" path="404.htm" responseMode="File" />    </httpErrors><rewrite> <rules> <rule name="Prevent hotlinking"> <match url="^.*\.(rar|zip|7z)$" ignoreCase="true" /> <conditions>            <add input="{HTTP_REFERER}" pattern="//www.iis7.com/.*" negate="true" />            <add input="{HTTP_REFERER}" pattern="http://m.jb51.net/.*" negate="true" />            <add input="{HTTP_REFERER}" pattern="http://www.baidu.com/.*" negate="true" /> </conditions> <action type="Rewrite" url="/daolian.htm" /> </rule> </rules> </rewrite>   </system.webServer></configuration>

    为了更深入的学习,希望大家继续看一下下面的图文教程

    主要是简单介绍一下url重写的配置,如果上面的规则放置位置没问题,打开url重写

    看如下图所示内容没问题就说明配置文件正常,否则按照上面IIS7站长之家给出的完整示例修改即可

    配置过程中的测试

    模式:^.*\.(rar|zip|7z)$

    编辑条件:

    {HTTP_REFERER}

    与模式不匹配(才触发条件)

    模式:网址匹配(//www.iis7.com/.*)单独的www域名,如果更多的二级域名呢

    IIS7站长之家小编更喜欢