[nginx]禁止訪問目錄下的某些擴展名文件
阿新 • • 發佈:2018-03-11
connect sse gpo ati AR oot windows body HR
禁止訪問目錄下的某些擴展名文件
這次我測一下,禁止訪問網站目錄下的 html/images/*.txt文件
[root@n1 nginx]# tree html/
html/
├── 50x.html
├── images
│?? └── maotai.txt
└── index.html
- 默認是允許訪問的,http://192.168.2.11/images/maotai.txt
- 設置禁止訪問
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]禁止訪問目錄下的某些擴展名文件