华域联盟 Linux 如何在Apache和Nginx禁止上传目录里PHP的执行权限

如何在Apache和Nginx禁止上传目录里PHP的执行权限

Apache下禁止指定目录运行PHP脚本

在虚拟主机配置文件中增加php_flag engine off指令即可,配置如下:

 Options FollowSymLinks
 AllowOverride None
 Order allow,deny
 Allow from all 
 php_flag engine off

另外一种方法,是设置在htaccess里面的,这个方法比较灵活一点,针对那些没有apapche安全操作权限的网站管理员:
Apache环境规则内容如下:Apache执行php脚本限制 把这些规则添加到.htaccess文件中
代码如下:

RewriteEngine on RewriteCond % !^$
RewriteRule uploads/(.*).(php)$ � [F]
RewriteRule data/(.*).(php)$ � [F]
RewriteRule templets/(.*).(php)$ �[F]

Nginx下禁止指定目录运行PHP脚本

Nginx更简单,直接通过location条件匹配定位后进行权限禁止,可在server配置段中增加如下的配置。

如果是单个目录:

location ~* ^/uploads/.*\.(php|php5)$
{
 deny all;
}

如果是多个目录:

location ~* ^/(attachments|uploads)/.*\.(php|php5)$
{
 deny all;
}

注意:这段配置文件一定要放在下面配置的前面才可以生效。

location ~ \.php$ {
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include    fastcgi_params;
}

最后给一个完整的配置示例

location ~ /mm/(data|uploads|templets)/*.(php)$ {
 deny all;
}

location ~ .php$ {
 try_files $uri /404.html;
 fastcgi_pass  127.0.0.1:9000;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include    fastcgi_params;
}

配置完后记得重启Nginx生效。

您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » 如何在Apache和Nginx禁止上传目录里PHP的执行权限

转载请保留出处和原文链接:https://www.cnhackhy.com/51323.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部