K
K
karpo5182018-06-10 17:44:06
Nginx
karpo518, 2018-06-10 17:44:06

http_secure_link not working. What is the reason?

I'm trying to set up http_secure_link. The most simplified test:

location ~ \.mp4$ {
            
            secure_link $arg_md5,$arg_expires;
            secure_link_md5 "test";

            if ($secure_link = "") { return 403; }
            if ($secure_link = "0") { return 410; }

            mp4;
            mp4_buffer_size 1m;
            mp4_max_buffer_size 5m;
        }

function buildSecureLink($url)
{
    $ttl = 10000;    
    $expires = time() + $ttl;
    $md5 = md5("test", true);
    $md5 = base64_encode($md5);
    $md5 = strtr($md5, '+/', '-_');
    $md5 = str_replace('=', '', $md5);
    
    if(strpos($url, '?') !== false)
    {
    	return $url . '&md5=' . $md5 . '&expires=' . $expires;
    }

    return $url . '?md5=' . $md5 . '&expires=' . $expires;
}

returns a 403 response. I come to the conclusion that php and nginx create different md5. What is the reason? I request
echo -n 'test' |     openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =

And I get the same hash that is contained in the url. The code matches and should work correctly
1. Why doesn't it work?
2. How can I debug?
3. Is there a way to see the real value of the hash parameter against which the get parameter is being compared?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question