czwartek, 23 maja 2013

nginx - secure download


http://wiki.nginx.org/HttpSecureLinkModule
location ~ ^/download/([a-zA-Z0-9_-]+)/([0-9]+)/(.*)$ {
                set $x_uri_hash $1;
                set $x_uri_expires $2;
                set $x_uri_file $3;
                secure_link $x_uri_hash,$x_uri_expires;
                secure_link_md5 SECRETTOKEN$x_uri_file$x_uri_expires;
                if ($secure_link = "") {
                       rewrite ^ /error/access_denied.html last;
                }
                if ($secure_link = "0") {
                       rewrite ^ /error/access_expired.html last;
                }
                rewrite ^ /files/$x_uri_file last
}
location /error/ {
            root /storage/download;
            internal;
 }
location /files/ {
            root /storage/download;
            set $limit_rate  512k;
            internal;
}

nginx - log format dla vhosta

       log_format  vhost '$http_host $remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent"';

        access_log /var/log/nginx/access.log vhost;