nginx webdav secure_link

2015-09-30 13:33  1924人阅读  评论 (0)

利用nginx的webdav模块和secure_link模块实现简单的上传功能

server {
    listen       80;
    server_name  dotcoo.com;

    root   /home/www/dotcoo.com;

    create_full_put_path  on;
    dav_access  group:rw  all:r;

    location / {
        index  index.html index.htm;
    }

    location ~ \.(jpg|jpeg|png|gif)$ {
        dav_methods PUT;

        secure_link $arg_md5,$arg_expires;
        secure_link_md5 "$secure_link_expires$uri$remote_addr secret";

        set $ok 0;
        if ($request_method = "PUT") {
            set $ok 1;
        }
        if ($secure_link = "") {
            set $ok "{ok}1";
        }
        if ($secure_link = "0") {
            set $ok "{ok}2";
        }
        if ($ok = "11") {
            return 403;
        }
        if ($ok = "12") {
            return 410;
        }
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}