首页 Nginx nginx – 拒绝所有被另一个位置块覆盖

nginx – 拒绝所有被另一个位置块覆盖

location /_private { deny all; } location ~ .php${ # Workaround PHP vulnerability: # http://forum.nginx.org/read.php?2,88845,page=3 try_files $uri =404;

location /_private {
    deny    all;
}

location ~ \.php${
    # Workaround PHP vulnerability:
    # http://forum.nginx.org/read.php?2,88845,page=3
    try_files   $uri =404;

    include /etc/nginx/fastcgi_params;
    keepalive_timeout 0;

    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass    unix:/tmp/php.socket;
}

我想拒绝访问_private目录中的所有内容.
当我尝试访问_private / a时,我得到403错误,就像应该这样.但是当我尝试访问_private / b.php时,拒绝所有部分完全被忽略.
最佳答案
使您的/ _private位置优先于正则表达式匹配:

location ^~ /_private {

而已.

nginx documentation具有关于哪个位置块将应用于给定请求的良好信息.报价:

  1. Directives with the “=” prefix that match the query exactly. If found,searching stops.
  2. All remaining directives with conventional strings. If this match used the “^~” prefix,searching stops.
  3. Regular expressions,in the order they are defined in the configuration file.
  4. If #3 yielded a match,that result is used. Otherwise,the match from #2 is used.

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/yunying/nginx/20201019/11285.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部