点赞
评论
收藏
分享
举报
Nginx防盗链
发表于2020-08-29 13:50

浏览 727

配置Nginx防盗链和配置过期时间、不记录日志都用到location,所以可以把两部分写在一起,如下所示:

[root@minglinux-01 ~] vim /usr/local/nginx/conf/vhost/test.com.conf
···
12 location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
//~* 表示后面的关键词不区分大小写
13 {
14 expires 7d;
15 valid_referers none blocked server_names *.test.com ;
16 if ($invalid_referer) { //$invalid referer表示无效的referer
17 return 403;
18 }
19 access_log off;
20 }
···

测试

[root@minglinux-01 ~] /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@minglinux-01 ~] /usr/local/nginx/sbin/nginx -s reload
[root@minglinux-01 ~] curl -x127.0.0.1:80 -e "http://www.baidu.com" test.com/1.gif -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.2
Date: Wed, 28 Nov 2018 13:02:18 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
[root@minglinux-01 ~] curl -x127.0.0.1:80 -e "http://www.test.com" test.com/1.gif -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Wed, 28 Nov 2018 13:02:25 GMT
Content-Type: image/gif
Content-Length: 2
Last-Modified: Tue, 27 Nov 2018 15:00:53 GMT
Connection: keep-alive
ETag: "5bfd5c25-2"
Expires: Wed, 05 Dec 2018 13:02:25 GMT
Cache-Control: max-age=604800
Accept-Ranges: bytes

防盗链配置成功,而且不仅仅有防盗链的功能,还有过期时间。

已修改于2023-03-08 02:22
创作不易,留下一份鼓励
守望

暂无个人介绍

关注



写下您的评论
发表评论
全部评论(0)

按点赞数排序

按时间排序

关于作者
守望
这家伙很懒还未留下介绍~
89
文章
0
问答
17
粉丝
相关文章
转载:https://linux.cn/article-5985-1.html作者: KYoung译者: LCTT struggling如何获取你所需要的NGINX指标如何获取需要的指标取决于你正在使用的NGINX版本以及你希望看到哪些指标。(参见 如何监控NGINX(第一篇) 来深入了解NGINX指标。)自由开源的NGINX和商业版的NGINXPlus都有可以报告指标度量的状态模块,NGINX也可以在其日志中配置输出特定指标:指标可用性 指标NGINX(开源)  NGINXPlus NGINX日志 accepts(接受)/accepted(已接受) x x  handled(已处理) x x  dropped(已丢弃) x x  active(活跃) x x  requests(请求数)/tot
点赞 4
浏览 1.3k
我们很高兴地宣布推出NGINXIngressController版本1.9.0。此版本建立在Kubernetes平台(包括RedHatOpenShift、AmazonElasticContainerServiceforKubernetes(EKS)、AzureKubernetesService(AKS)、GoogleKubernetesEngine(GKE)、IBMCloudPrivate、Diamanti等)Ingress负载均衡解决方案的持续开发基础之上。版本1.9.0的推出充分彰显了我们致力于提供灵活、强大且易用的IngressController的承诺,它Controller可以对KubernetesIngress资源和NGINXIngress资源进行配置:• KubernetesIngress资源提供了IngressController实施的极致兼容性,并且可使用注释和自定义模板进行扩展,以生成复杂配置。• NGINXIngress资源提供特定的NGINX配置方案,与自定义通用Kuber
点赞 0
浏览 1.1k
又是一个热情似火的六月,一年一度的 Microservices June 微服务之月再次回归!微服务之月是 NGINX 一年一度的免费线上教学项目,今年我们将主要关注“微服务交付”的概念和技巧。完成课
点赞 1
浏览 660