nginx禁止直接访问目录或文件
IOS辅助 2026-09-03 14:06:28
0
nginx禁止直接访问目录或文件,禁接访如果不禁止,止直nginx会直接去下载web目录下文件 ,问目文件如果有配置文件,录或并可以直接裸露一些配置文件源代码 。禁接访
禁止访问某些后缀文件
<a target="_blank" href="https://www.kaiyuanyuanma.com/tag/416.html" title="View all posts in location">location</a>~ \.(ini|conf|txt)$ {deny all;}location ~ \.(ini|conf|txt)$ { deny all;}location ~ \.(ini|conf|txt)$ { deny all;}
禁止访问目录或目录下文件
#禁止访问目录location ^~ /test/ {deny all;}#禁止访问目录location ^~ /test/ { deny all;}#禁止访问目录location ^~ /test/ { deny all;}
#禁止访问目录下文件location ^~ /test {deny all;}#禁止访问目录下文件location ^~ /test { deny all;}#禁止访问目录下文件location ^~ /test { deny all;}
nginx location 匹配相关
= 表示精确匹配
^~ 表示uri以某个字符串开头
~ 正则匹配(区分大小写)
~* 正则匹配(不区分大小写) !~和!~*分别为区分大小写不匹配及不区分大小写不匹配的止直正则
/ 任何请求城市匹配
nginx配置图片直接下载不打开
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {add_header Content-Disposition attachment;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { add_header Content-Disposition attachment; }location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { add_header Content-Disposition attachment; }
内容校验完了