# Nginx HttpSecureLinkModule php streaming

**URL:** <https://www.ruby-forum.com/t/nginx-httpsecurelinkmodule-php-streaming/244354>\
**Category:** NGINX\
**Created:** [March 26, 2016, 3:01am UTC](https://www.ruby-forum.com/t/nginx-httpsecurelinkmodule-php-streaming/244354 "2016-03-26T03:01:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [March 26, 2016, 3:01am UTC](https://www.ruby-forum.com/t/nginx-httpsecurelinkmodule-php-streaming/244354/1 "2016-03-26T03:01:41Z")

</div>

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  
[http://nginx.org/en/docs/http/ngx\_http\_secure\_link\_module.html#variables](http://nginx.org/en/docs/http/ngx_http_secure_link_module.html#variables)

> <https://stackoverflow.com/questions/8848919/secure-pseudo-streaming-flv-files/8863219#8863219>

> <https://stackoverflow.com/questions/27468743/nginx-secure-link-module-not-working-with-php-files-but-working-on-static-files>

> <https://stackoverflow.com/questions/30065870/nginx-httpsecurelinkmodule-php-example>

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

[http://domain.tld/videos/529d86c4ff560cb559df7eb794aeb4b1/56f5bec4/5/4/d/f/e/54dfee5c43e6e.mp4](http://domain.tld/videos/529d86c4ff560cb559df7eb794aeb4b1/56f5bec4/5/4/d/f/e/54dfee5c43e6e.mp4)

real path for this video is

```
/var/www/domain.tld/media/videos/5/4/d/f/e/54dfee5c43e6e.mp4

```

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/](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;
    mp4_buffer_size 1m;
    mp4_max_buffer_size 5m;
    gzip off;

  }

location ~ \.flv$ {

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

  flv;
  }
}

```

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?

Posted at Nginx Forum:

> **[nginx HttpSecureLinkModule php streaming](https://forum.nginx.org/read.php?2,265663,265663#msg-265663)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![JoakimR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e68b1a/32.png) [@JoakimR](https://www.ruby-forum.com/u/JoakimR)\
**Post date:** [March 28, 2016, 12:00pm UTC](https://www.ruby-forum.com/t/nginx-httpsecurelinkmodule-php-streaming/244354/2 "2016-03-28T12:00:05Z")

</div>

Have strogled with this for 4 days now… could someone please help me?

Posted at Nginx Forum:

> **[Re: nginx HttpSecureLinkModule php streaming](https://forum.nginx.org/read.php?2,265663,265681#msg-265681)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![JoakimR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e68b1a/32.png) [@JoakimR](https://www.ruby-forum.com/u/JoakimR)\
**Post date:** [March 28, 2016, 5:36pm UTC](https://www.ruby-forum.com/t/nginx-httpsecurelinkmodule-php-streaming/244354/3 "2016-03-28T17:36:34Z")

</div>

On Fri, Mar 25, 2016 at 10:01:28PM -0400, JoakimR wrote:

Hi there,

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

I’m not sure what specifically your question is.

If it is “how do I use the nginx secure-link module?”, then the content  
at [Module ngx\_http\_secure\_link\_module](http://nginx.org/en/docs/http/ngx_http_secure_link_module.html) should  
be helpful.

If it is “how do I use the nginx secure-link module with mp4 streams?”,  
then the first hit on a web search for “site:nginx.org secure link mp4”  
for me is [https://forum.nginx.org/read.php?2,228161,228183](https://forum.nginx.org/read.php?2,228161,228183) which seems  
to show a working example.

If it is “how do I create the url in php?”, then the shell examples on  
the first page should give a hint; just implement that in php.

> 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

That makes it sound like the question is “how do I use the nginx  
secure-link module, when the algorithm to create the link can be  
anything  
at all?”.

And the answer there is “you don’t”.

If you want your own secure-link creation system, you write your own  
module to match that. If you want to use the nginx secure-link module,  
you write you external link-creation tool to match it.

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

What request do you make for this test? What values do these variables  
have, when nginx receives that request?

> 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?

Start small. What is the first specific thing you want to do?

Do you have it working? If not, what do you have, what do you do, what  
response do you get, what response do you want?

Repeat, for each other specific thing that you want to do.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
