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;

    include /etc/Nginx/fastcgi_params;
    keepalive_timeout 0;

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

我想拒绝访问_private目录中的所有内容.@H_403_7@当我尝试访问_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.f2er.com/nginx/435143.html

猜你在找的Nginx相关文章