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

在虚拟主机配置文件中增加php_flag engine off指令即可,配置如下
"/website/uploads"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all php_flag engine off 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; }

售后响应及时
7×24小时客服热线
数据备份
更安全、更高效、更稳定
价格公道精准
项目经理精准报价不弄虚作假
合作无风险
重合同讲信誉,无效全额退款