apache tomcat|Apache 或 Nginx 下禁止站点或附件目录运行 PHP 脚本

时间:2020-01-01  来源:apache  阅读:


如果上传目录被植入 PHP 文件,即可远程执行。为了安全起见,我们一般会对上传目录禁止运行 PHP 脚本。

在 Apache 下面我们可以通过一下方法来禁止运行 PHP 脚本:

 
php_flag engine off 
 

Nginx 方法如下:

location /wp-content/uploads/ { 
 location ~ .*\.(php)?$ { 
 deny all; 
 } 

而对于多个目录的话,可以一起进行限定:

location ~* ^/(uploads|images)/.*\.(php|php5)$ 

deny all; 


lighthttpd

$HTTP["url"] =~ "^/(forumdata|templates|upload|images)/" {
 fastcgi.server = ()
}

例子,WordPress附件目录禁止运行PHP

我用的是nginx,说说禁止方法:

location /wp-content/uploads/ {
    location ~ .*\.(php)?$ {
        deny all;
    }
}

插入你的nginx conf中,重启nginx即可。
附上一个完整的虚拟主机的例子供参考:

server
{
listen 80;
server_name bbs.vpser.net;
index index.html index.htm index.php;
root /home/wwwroot/bbs.vpser.net;include discuz.conf;
location /wp-content/uploads/ {
location ~ .*\.(php)?$ {
deny all;
}
location ~ .*.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
access_log off;
}

添加完执行:/usr/local/nginx/sbin/nginx -t测试配置文件,执行:/usr/local/nginx/sbin/nginx -s reload 载入配置文件使其生效.

apache tomcat|Apache 或 Nginx 下禁止站点或附件目录运行 PHP 脚本

http://m.bbyears.com/jiaocheng/84124.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新