【发布时间】:2016-03-18 15:54:13
【问题描述】:
我有一个目录 (/var/www/private/)。此目录中有三个文件(1.txt、2.txt、3.txt)。
我想拒绝每个人访问整个目录和这三个文件,但有时我想授予对该目录中特定 IP 和特定文件的访问权限。
在“block.conf”文件中,我将列出授予访问权限的文件和 IP 地址。我需要 nginx 读取此文件并相应地拒绝/允许访问(无需在每次更改文件时重新加载 nginx)。
例如在block.conf中:
#denies access to all files in private directory
location /private {
deny all;
}
#allows below IP access to 2.txt
location /private/2.txt {
allow 5.3.7.0;
}
#allows below IP addresses access to 1.txt
location /private/1.txt {
allow 3.5.7.2;
allow 9.7.2.2
}
block.conf 文件中的位置和 IP 地址会经常用 PHP 编辑,我希望 nginx 相应地拒绝/允许对该文件的访问。
我认为这很容易实现,但存在一些问题:
- nginx 在启动时只读取一次 block.conf,不允许我 动态修改访问(无需重新加载 nginx)
- location 指令不能在 block.conf 文件中,不是 允许我设置对特定文件的访问权限
如果 nginx 的 access mod 无法做到这一点,那我该怎么做呢?如果nginx做不到,还有其他软件可以吗?
【问题讨论】:
-
现在好像可以了,可惜只在商业版的nginx中。见docs.nginx.com/nginx/admin-guide/security-controls/…
标签: php security http nginx server