Knowledgebase
Nginx ngx_http_secure_link_module on Tube Script V6
Posted by Konrad Piwowar on 21 September 2016 07:54 AM

* Please Note *
This article is informational only - we do not provide free technical support for nginx - only for our software. If you would like us to set this up for you, we can do so but will charge for the labour.


NGINX CONFIGURATION
-------------------
Goes into server {...} for appropriate vhost after server_name. Please make sure to change YOURSECRETKEYGOESHERE. Restart Nginx.
 
location ~* .(mp4)$ {
    secure_link $arg_md5,$arg_expires;
    secure_link_md5 "$secure_link_expires YOURSECRETKEYGOESHERE";
    if ($secure_link = "") {  return 403; }
    if ($secure_link = "0") { return 410; }
}



NGINX FUNCTION
--------------
Please paste the following function in functions.custom.php in the /admin/ directory. Make sure to replace YOURSECRETKEYGOESHERE with the one you used in nginx configuration.

function nginxSecureLink($array) {
    //hashing function for ngx_http_secure_link_module
    global $video_url;
    $rrow = $array[0];
    $filename = $array[1];
    $server = dbQuery("SELECT * FROM servers WHERE record_num = $rrow[server]");
    $server = $server[0];
    $server['hash_key'] = "YOURSECRETKEYGOESHERE";
    $subdir = $rrow[filename][0] . '/' . $rrow[filename][1] . '/' . $rrow[filename][2] . '/' . $rrow[filename][3] . '/' . $rrow[filename][4] . '/';
    $output = $video_url . '/' . $subdir . $rrow[$filename];
    $expires = time()+3600;
    $md5hash = trim(shell_exec("echo -n '".$expires." $server[hash_key]' | openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d ="));
    return $output."?md5=$md5hash&expires=$expires";

}



SCRIPT CONFIGURATION
-----------------------------
1) Open functions.player.php, and copy the the "displayPlayerVideoJS" function into admin/functions.custom.php
2) Rename the function at the top to "displayPlayerVideoJSNginx"
3) Please make the following changes:

Replace:
$defaultFile = $outputFiles['trailer_filename'];

With:
$outputFiles['trailer_filename'] = call_user_func('nginxSecureLink', array($rrow, 'trailer_filename'));
$defaultFile = $outputFiles['trailer_filename'];

-----


Replace:
$defaultFile = $outputFiles['mobile'];

With:
$outputFiles['mobile'] = call_user_func('nginxSecureLink', array($rrow, 'mobile'));
$defaultFile = $outputFiles['mobile'];

-----

Replace:
$defaultFile = $outputFiles['filename'];

With:
$outputFiles['filename'] = call_user_func('nginxSecureLink', array($rrow, 'filename'));
$defaultFile = $outputFiles['filename'];

-----

Once you have made these changes, save the file.

4) Open template.video_content.php for the template you are using, and replace "displayPlayerVideoJS" with "displayPlayerVideoJSNginx"
5) Test to make sure everything worked

(1 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments: