Welcome! Log In Create A New Profile


nginx HttpSecureLinkModule php streaming

March 25, 2016 10:01PM
I have for hours been trying to understand and figure out how this is working, and searched and tried a lot, but still.... No hair left on my head :(

Sources for trial and errors

The question is how do I get Nginx and php to make a timed encrypted link to play a video?

The final output should be looking like


real path for this video is


The php snippet that should be left unaltered if possible, since it will be updated from time to time from the developer. So all modifications have to made in NginX

//generate lighttpd hash
function getMediaLink($filename) {
global $modsec_secret; // example: s3cr3tk3y (from your lighttpd config)
global $modsec_url; // example: http://media.asfd.com/dl/ with trailing slash
$filename = rawurldecode($filename);
$f = "/".$filename;
$t = time();
$t_hex = sprintf("%08x", $t);
$m = md5($modsec_secret.$f.$t_hex);
$link = $modsec_url.$m.'/'.$t_hex.$f;
return $link;

And to the NginX conf file i have this head:

server {
listen 80; # http2;
server_name localhost;
index index.php index.html index.htm;

#charset koi8-r;
access_log /var/log/nginx/access.log main;
root /var/www/domain.tld;

location / {

..... (the latest attempt)

location /videos/ {
secure_link $arg_st,$arg_e;
secure_link_md5 secretstring$uri$arg_e;

location ~ \.mp4$ {

if ($secure_link = "") {
return 403;

mp4_buffer_size 1m;
mp4_max_buffer_size 5m;
gzip off;


location ~ \.flv$ {

if ($secure_link = "") {
return 403;


Could some one please try to tell me how to make this happen, but maybe more important why, in a passion that mae me understand how and why?
Subject Author Posted

nginx HttpSecureLinkModule php streaming

JoakimR March 25, 2016 10:01PM

Re: nginx HttpSecureLinkModule php streaming

JoakimR March 28, 2016 05:59AM

Re: nginx HttpSecureLinkModule php streaming

Francis Daly March 28, 2016 11:38AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 346
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready