Nginx作为静态资源web服务_防盗链配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/longgeqiaojie304/article/details/85047539

Nginx作为静态资源web服务_防盗链配置

1、新建http_referer.html文件

(1)touch http_referer.html

    

(2)编辑http_referer.html文件

    

http_referer.html代码:

<html>

    <head>http_referer test</head>

<body>

    <h1>Welcome to http_referer!!!!</h1>

    <image src="http://193.112.108.135/dragon.jpg"/>

</body>

</html>

2、发起http://193.112.108.135/http_referer.html请求

(1)浏览器发起请求

    

(2)Linux服务器下模拟发起请求

    curl http://193.112.108.135/http_referer.html

    

(3)查看nginx access.log日志文件

    访问"GET /dragon.jpg HTTP/1.1"请求

    $http_referer = "http://193.112.108.135/http_referer.html"

    

3、nginx增加防盗链配置

    如果访问ip不是193.112.108.135就会出现403 Forbidden报错提示

    

4、验证防盗链配置是否生效

(1)浏览器验证

    使用ip=193.112.108.135访问正常:

    

    使用域名dragonbrother.1.com访问报错:

    

(2)Linux服务器下验证

    使用ip=193.112.108.135访问正常:

    

    使用别人的域名www.baidu.com域名访问报错:(说明不允许其他网站盗用自己网站资源)

    

    使用自己的域名dragonbrother.1.com访问报错:

    

(3)允许其他网站访问自己网站资源配置

    

    允许www.baidu.com访问我的图片资源

    

    允许http://nginx.org/访问我的图片资源
    

    允许https://translate.google.cn/访问我的图片资源

    

猜你喜欢

转载自blog.csdn.net/longgeqiaojie304/article/details/85047539
今日推荐