防止IIS 10无法进行热链接-Windows Server 2016 [英] Prevent Hotlinking not working IIS 10 - Windows server 2016

查看:54
本文介绍了防止IIS 10无法进行热链接-Windows Server 2016的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何防止在IIS 10上进行热链接-web.config.我在Google上找到了一个解决方案,但似乎不起作用,这是我的代码:

 <规则名称=防止热链接" stopProcessing ="true">< match url =.* \.(png | jpe?g | gif)"/><条件><添加input ="{HTTP_REFERER}" pattern ="^ $" negate ="true"/><添加输入="{HTTP_REFERER}" pattern ="^ https?://((m \.)?domain \ .com/.*$" negate ="true"/></conditions>< action type ="Rewrite" url ="/assets/images/hotlinking.png"/></rule> 

任何想法:(?非常感谢.

解决方案

作为网站开发人员,有时不希望直接引用我们自己网站上的图像并将其显示在其他人的网站上.在某些情况下,它可能会为我们的数据中心带来大量的网络带宽,这意味着我们要花钱来支付使用图像的用户的费用.

例如,您的网站是www.sample1.com,您在

如果用户登陆www.sample2.com并访问

如果仍然无法正常工作,请尝试禁用缓存,然后重试.

如果要阻止多个站点,则还可以使用重写映射并设置站点列表.

 < system.webServer>< rewrite><规则><规则名称=黑名单阻止" stopProcessing ="true">< match url =(?: jpg | jpeg | png | gif | bmp)$"/><条件><添加输入="{HTTP_REFERER}" pattern ="^ https?://(.+?)/.*$"/><添加输入="{DomainsBlackList:{C:1}}" pattern ="^ block $"/><添加输入="{REQUEST_FILENAME}" pattern ="splog.png" negate ="true"/></conditions>< action type ="Redirect" url ="http://www.hanselman.com/images/splog.png" appendQueryString ="false" redirectType ="Temporary"/></rule></rules>< rewriteMaps>< rewriteMap name ="DomainsBlackList" defaultValue ="allow"><添加key ="google-chrome-browser.com" value =阻止"/><添加key ="www.verybadguy.com" value =阻止"/><添加key ="www.superbadguy.com" value =阻止"/></rewriteMap></rewriteMaps></rewrite></system.webServer> 

I don't know how to prevent hotlinking on IIS 10 - web.config. I found a solution on google, but it seems not working, this is my code:

            <rule name="Hotlinking Preventing" stopProcessing="true">
                <match url=".*\.(png|jpe?g|gif)" />
                <conditions>
                    <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
                    <add input="{HTTP_REFERER}" pattern="^https?://(m\.)?domain\.com/.*$" negate="true" />
                </conditions>
                <action type="Rewrite" url="/assets/images/hotlinking.png" />
            </rule>

Any idea :( ? Thank you so much.

解决方案

As a website developer sometimes don't want the images on our own website to be directly referenced and showed on other's website. It can cause a lot network bandwidth for our datacenters in some cases, which means costing money for us to pay for the one who uses our images.

For example, your website is www.sample1.com, you have an image on http://www.sample1.com/test.jpg and www.sample2.com used your image on www.sample2.com by putting a tag in their HTML, it can cause network request going into your server consuming your resources.

if the user lands on www.sample2.com visiting http://www.sample1.com/test.jpg, for www.sample1.com's web server, the HTTP request for this particular image will have an HTTP header named "referer" with a value of "http://www.sample1.com....". This is where we will check and block the request.

url rewrite rule:

 <rule name="Prevent Image Hotlinking">
<match url=".*\.(jpg|jpeg|png|gif|bmp)$" />
<conditions>
                    <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
                    <add input="{HTTP_REFERER}" pattern="^http://www.sample1.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/img/no_hotlinking.png" />

If it still not work try to disable the cache and try again.

if you want to block multiple sites then you could also use the rewrite map and set the list of the site.

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Blacklist block" stopProcessing="true">
          <match url="(?:jpg|jpeg|png|gif|bmp)$" />
          <conditions>
              <add input="{HTTP_REFERER}" pattern="^https?://(.+?)/.*$" />
              <add input="{DomainsBlackList:{C:1}}" pattern="^block$" />
              <add input="{REQUEST_FILENAME}" pattern="splog.png" negate="true" />
          </conditions>
          <action type="Redirect" url="http://www.hanselman.com/images/splog.png" appendQueryString="false" redirectType="Temporary"/>
      </rule>
    </rules>
    <rewriteMaps>
              <rewriteMap name="DomainsBlackList" defaultValue="allow">
                  <add key="google-chrome-browser.com" value="block" />
                  <add key="www.verybadguy.com" value="block" />
                  <add key="www.superbadguy.com" value="block" />
              </rewriteMap>
    </rewriteMaps>
  </rewrite>
</system.webServer>

这篇关于防止IIS 10无法进行热链接-Windows Server 2016的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆