nginx 配置禁止访问某个目录或文件

在nginx要禁止某个或一类资源,只需要增加一个location,然后在其中使用deny all即可。

禁止访问扩展名为text的文件,配置如下:

复制代码
location ~* /.text{
    deny all;
}

禁止访问docs目录,以及其下所有子目录或文件,配置如下:

复制代码
location ^~ /docs/ {
    deny all;
}

**注意:**上述docs后面的斜杠不能少,否则所有以docs开头的目录或文件都将禁止访问。

相关推荐
a***113522 分钟前
用nginx正向代理https网站
运维·nginx·https
m***11901 小时前
Ubuntu 系统下安装 Nginx
数据库·nginx·ubuntu
w***15314 小时前
四、nginx的优化和location匹配规则
运维·nginx
我不是张鸭鸭4 小时前
nginx的https的搭建
运维·nginx·https
007php0074 小时前
nginx加速缓存导致Event-Stream消息延迟问题的解决方案
运维·网络·数据库·nginx·缓存·面试·职场和发展
O***Z6164 小时前
httpslocalhostindex 配置的nginx,一刷新就报404了
运维·nginx
f***24114 小时前
不常用,总是忘记:nginx 重启指令
运维·windows·nginx
007php0075 小时前
nginx面试之负载均衡的实际经历与配置
运维·数据库·mysql·nginx·面试·职场和发展·负载均衡
6***v4175 小时前
启动nginx报错nginx [emerg] bind() to 0.0.0.080 failed (98 Address already in use)
运维·nginx
last demo6 小时前
smb服务器
linux·运维·服务器·nginx