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

[nginx]禁止访问目录下的某些扩展名文件

时间:2018-03-11 14:21:50      阅读:1602      评论:0      收藏:0      [点我收藏+]

标签:end   tree   page   nginx   stream   host   ref   window   ota   

禁止访问目录下的某些扩展名文件

这次我测一下,禁止访问网站目录下的 html/images/*.txt文件

[root@n1 nginx]# tree html/
html/
├── 50x.html
├── images
│?? └── maotai.txt
└── index.html

技术分享图片

  • 设置禁止访问
location ~ ^/images/.*\.(txt|php|php5|sh|pl|py|html)$
{
    deny all;
}

技术分享图片

  • 日志查看
- access.log: 允许访问
192.168.2.1 - - [11/Mar/2018:10:58:06 +0800] "GET /images/maotai.txt HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"

- access.log: 禁止访问
192.168.2.1 - - [11/Mar/2018:10:59:10 +0800] "GET /images/maotai.txt HTTP/1.1" 403 563 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"

- error.log
2018/03/11 10:59:10 [error] 28357#0: *16 access forbidden by rule, client: 192.168.2.1, server: localhost, request: "GET /images/maotai.txt HTTP/1.1", host: "192.168.2.11"

附录: nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location ~ ^/images/.*\.(txt|php|php5|sh|pl|py|html)$
        {
            deny all;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

[nginx]禁止访问目录下的某些扩展名文件

标签:end   tree   page   nginx   stream   host   ref   window   ota   

原文地址:https://www.cnblogs.com/iiiiher/p/8543506.html

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