码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 配置静态文件过期时间&防盗链

时间:2016-12-03 02:53:29      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:nginx 配置静态文件过期时间&防盗链

[root@LNMP ~]# vim /usr/local/nginx/conf/vhosts/linux.conf

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

    {

          access_log off;

          expires 1d;  #过期时间 1天

    }

    location ~ .*\.(js|css)  #此也也可改为  \.(js|css)来匹配

    {     access_log off;

          expires 2h;

    }


[root@LNMP ~]# /usr/local/nginx/sbin/nginx  -t  #检测        

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@LNMP ~]# /usr/local/nginx/sbin/nginx  -s reload #重新加载

[root@LNMP ~]# 


[root@LNMP ~]# curl -x 127.0.0.1:80 ‘http://www.linux.com/static/image/smiley/default/smile.gif‘ -I

技术分享配置缓存的目的,提高访问的速度,节省带宽。


-----------分割线-------------------------------------------------

Nginx  防盗链配置   2016-12-02  15:20


[root@LNMP ~]# vim /usr/local/nginx/conf/vhosts/linux.conf


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

    {

          access_log off;

          expires 1d;

          valid_referers  none blocked *.linux.com *.test.com; #访问白明单

          if ($invalid_referer)

          {

                return 403;  #返回 403

          }

#红色字体是新加的防盗链,配置。


测试如下图

技术分享以下是白明单访问

技术分享技术分享

本文出自 “CBO#Boy_Linux之路” 博客,请务必保留此出处http://20151213start.blog.51cto.com/9472657/1878896

Nginx 配置静态文件过期时间&防盗链

标签:nginx 配置静态文件过期时间&防盗链

原文地址:http://20151213start.blog.51cto.com/9472657/1878896

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!