Nginx、Apache、Lighttpd禁止目录执行php配置示例

为了加强网站安全性,我们除了限制目录权限外,还需要禁用某此目录禁止执行php。在IIS中可以直接将目录的脚本执行权限去掉,而针对非windows系统如何做呢?

接下来的文章将简单的介绍不同的webserver如何禁用php执行。。。。

Apache:

代码如下:
<Directory /website/attachments>
    php_flag engine off
</Directory>

Nginx:

禁用单个目录:

代码如下:
location /upload/ {
  location ~ .*.(php)?$
    {
      deny all;
    }
  }

禁用多个目录:

代码如下:
location ~* ^/(upload|images)/.*.(php|php5)$
{
    deny all;
}

Lighthttpd:

代码如下:
$HTTP["url"] =~ “^/(forumdata|templates|customavatars?)/” {
    fastcgi.server = ()
}

Apache

<Location “/forumdata”>
    php_admin_flag engine off
    Options -ExecCGI
    AddType text/plain .html .htm .shtml .php
</Location>

参与评论