nginx上传目录配置,禁止执行权限

我们经常会把网站的图片文件上传目录设置为只可上传文件但不能执行文件,就是要禁止执行权限,小编来给大家举一个上传目录配置,禁止执行权限方法,各位可参考。

如果不让有执行权限最简单的办法

 代码如下复制代码


location ~ ^/upload/.*.(php|php5)$ 

deny all; 
}

上面的方法满足不了我要求,后来找到一个不错的脚本

 代码如下复制代码

server
        {
                listen       80;
                server_name xxxx.com;
                index index.html index.htm index.php default.html default.htm default.php;
                root  /home/wwwroot/xxxx.com;


                include none.conf;


                #匹配多个上传目录
                location ~ ^/(Upload|Upload1)
                {
                        # 匹配文件最名包含两个.以上的文件
                        location ~ "([.]{2,})$"
                        {
                                deny all;
                        }
                        # 配置php和php5后缀
                        location ~ ".(php|php5)$"
                        {
                                deny all;
                        }
                }


                location ~ .*.(php|php5)?$
                {
                                try_files $uri =404;
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fcgi.conf;
                }


                location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
                {
                                expires      30d;
                }


                location ~ .*.(js|css)?$
                {
                                expires      12h;
                }


                access_log off;
        }

nginx下禁止dedecms目录php执行权限的配置方法。

如下配置即可:

 代码如下复制代码

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;
    includefastcgi_params;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值