Nginx配置防盗链
Nginx配置防盜鏈
進(jìn)入Nginx配置文件:
[root@LHQ vhosts]# vim test.conf
server
{
listen 80;
server_name www.test.com www.aaa.com www.bbb.com;
if ($host != 'www.test.com')
{
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log qiangzi;
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_usre_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
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; (可用的referer)
? ? ? ?if ($invalid_referer) ?(if:是如果的意思;valid_referers反義詞invalid_referer)
? ? ? ?{
? ? ? ? ? ?return 403;
? ? ? ?}
}
localtion ~\(js|css)
{
access_log off;
expires 2h;
}
location ~(static|cache)
{
access_log off;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
保存退出
查看文件是否有錯(cuò):
[root@LHQ vhosts]# /usr/local/nginx/sbin/nginx -t
[root@LHQ vhosts]# /usr/local/nginx/sbin/nginx -s reload ?(重新加載)
[root@LHQ vhosts]# curl -e "http://www.baidu.com/1111" -I -x127.0.0.1:80 '要做防盜鏈的網(wǎng)站圖片地址'
(選項(xiàng):-e指定referer;百度的referer不是真實(shí)存在的,只為做防盜鏈測試,如果是403則防盜鏈設(shè)置成功)
轉(zhuǎn)載于:https://blog.51cto.com/12360027/1936780
總結(jié)
以上是生活随笔為你收集整理的Nginx配置防盗链的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 修改 keystore密码
- 下一篇: 阿里配管专家解读:如何最优成本搭建非标准