阻止nginx中的文件夹和里面的所有内容,为localhost抛出404 EXCEPT。浏览器正在请求脚本下载

时间:2015-08-13 11:23:28

标签: nginx

这是我的代码:

# I had to do this one because going .com/restricted was throwing 403, not 404.
location /restricted {
    return 404;
}

#This seemed to work except I don't want localhost to have 404, I want it to access correctly
location ~ /restricted/(.+)\.php$ {
     deny all;
     return 404;
     allow 127.0.0.1;
}

所以,基本上:

  1. 每次NON-localhost尝试访问受限制的OR或其内容时获取404(例如/restricted/should_be_restricted_script.php
  2. 每当我尝试访问该文件夹时,浏览器会询问我是否要下载脚本...当我保存并打开它时,确实是should_be_restricted_script.php,我无法弄清楚为什么...
  3. 有人能帮助我吗? tyvm

1 个答案:

答案 0 :(得分:0)

我认为您应该替换denyallow行,因为第一场比赛将适用:

location ~ /restricted/(.+)\.php$ {
   allow 127.0.0.1;
   deny all;
}