nginx上傳目錄配置,禁止執行權限

咱們常常會把網站的圖片文件上傳目錄設置爲只可上傳文件但不能執行文件,就是要禁止執行權限,小編來給你們舉一個上傳目錄配置,禁止執行權限方法,各位可參考。php

若是不讓有執行權限最簡單的辦法css

 代碼以下 複製代碼


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

deny all; 
}html

上面的方法知足不了我要求,後來找到一個不錯的腳本nginx

 代碼以下 複製代碼

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;spa


                #匹配多個上傳目錄
                location ~ ^/(Upload|Upload1)
                {
                        # 匹配文件最名包含兩個.以上的文件
                        location ~ "([.]{2,})$"
                        {
                                deny all;
                        }
                        # 配置php和php5後綴
                        location ~ ".(php|php5)$"
                        {
                                deny all;
                        }
                }unix


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


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


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

相關文章
相關標籤/搜索