Created
May 2, 2011 20:19
-
-
Save mpbod/952277 to your computer and use it in GitHub Desktop.
Secured Download Link, nginx config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| location /secret_downloads/ { | |
| ## Set the root to the PARENT directory of your secret downloads. | |
| root /home/mpbod/; | |
| ## This must match the URI part related to the MD5 hash and expiration time. | |
| secure_link $arg_st,$arg_e; # this must match the URI part related | |
| ## This is how the MD5 hash is built from a secret token, an URI and an | |
| ## expiration time. | |
| secure_link_md5 mpbod$uri$arg_e; # 'mpbod' is the secret token | |
| ## If the hash is incorrect then $secure_link is a null string. | |
| if ($secure_link = "") { | |
| return 403; | |
| } | |
| ## The current local time is greater than the specified expiration time. | |
| if ($secure_link = "0") { | |
| return 403; | |
| } | |
| ## If everything is ok $secure_link is 1. | |
| ## This needs to be here otherwise you'll get a 404. | |
| rewrite ^/secret_downloads/(.*)$ /secret_downloads/$1 break; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment