我写这个来防止目录“下载”被访问,但从IP 1.2.3.4。
location ~ /folder/download { allow 1.2.3.4; deny all; return 403; }
但是,目录“文件夹”也被阻止,我不想这个。
我究竟做错了什么?
更新:
这里是所有真正的configuration:
server { server_name www.domain.com; rewrite ^ $scheme://domain.com$request_uri? permanent; } server { server_name atpc.info; access_log /var/log/nginx/atpc.info.access; error_log /var/log/nginx/atpc.info.error; root /var/www/atpc.info; location ^~ folder/download { allow 1.2.3.4; deny all; } location ^~ folder/includes { allow 1.2.3.4; deny all; } location ^~ folder/mythings { allow 1.2.3.4; deny all; } location ^~ folder/functions { allow 1.2.3.4; deny all; } location / { index index.htm index.php; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } location = /favicon.ico { return 204; access_log off; log_not_found off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ /\. { deny all; access_log off; log_not_found off; } }
谢谢。
你可能希望位置^〜而不是位置〜,因为前者是一个不允许regex覆盖的前缀匹配,而后者是一个正则expression式位置。 另外,取消返回403; 允许和拒绝指令对你的应用程序是足够的,并且返回将总是被评估,这意味着每个人将得到一个403。