nginx配置防盗链

1、编辑配置文件

vim /usr/local/nginx/conf/vhosts/test.conf 

2、修改以下位置开头

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf

改为

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|rar|zip|gz|bz2)$

    {

        access_log off;

        expires 15d;

        valid_referers none blocked *.test.com *.aaa.com *.bbb.com;

        if ($invalid_referer)

         {

             return 403;

          }

3、重新加载

/usr/local/nginx/sbin/nginx -s reload 

4、使用cure访问显示禁止访问配置成功

curl -e "http://www.baidu.com/111111" -I -x127.0.0.1:80 'http://www.test.com/static/image/common/online_supermod.gif'

HTTP/1.1 403 Forbidden

Server: nginx/1.6.3

Date: Mon, 30 May 2016 09:26:30 GMT

Content-Type: text/html

Content-Length: 168

Connection: keep-alive


你可能感兴趣的:(return,local,配置文件)