nginx HttpSecureLinkModule php example

2019-07-24 18:35发布

I have this configuration but I just can't make it work, Im having a hard time trying to figure it out..

I'm Trying get a fileserver under nginx using the HttpSecureLinkModule by making it with an expiration time..

Here's what I have in nginx:

 location /files/ {
    secure_link $arg_st,$arg_e;
    secure_link_md5 "secret$uri$arg_e";

    root /usr/share/nginx/www;
    if ($secure_link = "") {
            return 403;
    }
    if ($secure_link = 0) {
            return 410;
    }
}

And now In the remote server hiddenfile.php

<?php
$file="file/99/240182409124019248407098227489702";
$secret_word = "secret";
$uri_prefix = "http://domain.com/";
$time = time()+600;
$md5 = base64_encode(md5($secret_word.$file.$time, true));
$md5 = strtr($md5, '+/', '-_');
$md5 = str_replace('=', '', $md5);
$url= $uri_prefix.$file.'?st='.$md5.'&e='.$time;

?>

The result is something like this: http://domain.com/file/99/240182409124019248407098227489702?st=94ASFASF7SAF8AF9S898&e=38573287583

All I'm getting in the nginx's acceess.log is a 403 error..

Can anyone provide a simple example on how to do this? I've tried several things with no luck..

Thanks in advance...

标签: php nginx
1条回答
相关推荐>>
2楼-- · 2019-07-24 19:38

This was the answer for this question by Alexey Ten..

$uri in nginx starts with slash and in php you miss it –  Alexey Ten 14 hours ago 
查看更多
登录 后发表回答