nginx禁止直接访问目录或文件

nginx禁止直接访问目录或文件,禁接访如果不禁止,止直vmware云平台nginx会直接去获取web目录下文件,问目文件vmware云平台如果有配置文件,录或并可以直接暴露一些配置文件源代码。禁接访

禁止访问某些后缀文件

<a target="_blank" href="https://www.kaiyuanyuanma.com/tag/416.html" title="View all posts in location">location</a>~ \.(ini|conf|txt)$ { deny all; } <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 ^~ /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; } 内容看完了
皖ICP备2025077989号-141