nginx模块学习七 http_refer 防盗链

  • 语法
    Syntax: valid_referers none | blocked | server_names | string ...;
    Default: --
    Context:server,location

     

  1. 例/etc/nginx/conf.d/default.conf
    server {
        listen       80;
        server_name  localhost;
        
        sendfile on;
        #charset koi8-r;
        access_log  /var/log/nginx/log/static_access.log  main;
    
        
        location ~ .*\.(jpg|gif|png)$ {
            valid_referers none blocked 192.168.0.106 www.baidu.com;
            if ($invalid_referer) {
                return 403;
            }
            root  /opt/app/code/images;
        }
      
  2. 命令curl -I http://localhost/wei.png
    [root@promote conf.d]# curl -I http://localhost/wei.png
    HTTP/1.1 200 OK
    Server: nginx/1.14.0
    Date: Sat, 18 Aug 2018 13:13:09 GMT
    Content-Type: image/png
    Content-Length: 244044
    Last-Modified: Tue, 08 Aug 2017 09:17:25 GMT
    Connection: keep-alive
    ETag: "598981a5-3b94c"
    Accept-Ranges: bytes

     

  3. 命令curl -e "http://www.baidu.com"  -I http://localhost/wei.png

    [root@promote conf.d]# curl -e "http://www.baidu.com"  -I http://localhost/wei.png
    HTTP/1.1 200 OK
    Server: nginx/1.14.0
    Date: Sat, 18 Aug 2018 13:09:37 GMT
    Content-Type: image/png
    Content-Length: 244044
    Last-Modified: Tue, 08 Aug 2017 09:17:25 GMT
    Connection: keep-alive
    ETag: "598981a5-3b94c"
    Accept-Ranges: bytes

     

  4. 命令curl -e "http://www.google.com"  -I http://localhost/wei.png

    [root@promote conf.d]# curl -e "http://www.google.com"  -I http://localhost/wei.png
    HTTP/1.1 403 Forbidden
    Server: nginx/1.14.0
    Date: Sat, 18 Aug 2018 13:12:52 GMT
    Content-Type: text/html
    Content-Length: 169
    Connection: keep-alive
    

     

  5. 命令curl -e "http://192.168.0.106"  -I http://localhost/wei.png

    [root@promote conf.d]# curl -e "http://192.168.0.106"  -I http://localhost/wei.png
    HTTP/1.1 200 OK
    Server: nginx/1.14.0
    Date: Sat, 18 Aug 2018 12:58:27 GMT
    Content-Type: image/png
    Content-Length: 244044
    Last-Modified: Tue, 08 Aug 2017 09:17:25 GMT
    Connection: keep-alive
    ETag: "598981a5-3b94c"
    Accept-Ranges: bytes
    

     

转载于:https://my.oschina.net/langgege/blog/1930131

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值