B
B
bad_guy2013-09-22 17:21:39
PHP
bad_guy, 2013-09-22 17:21:39

Each user has a unique link to the file[NGINX, PHP]

Hello Jedi.
We set a task, I solve it not for the first day, but I can’t cope with it.

Task:
Each user is given a video file unique for him, like domen.tv/video/{hash}/file.mp4(flv)
hash consists of the user's ip and salt.
It is necessary that this link opens only for this user.
The file storage structure is as follows (you can change it):

domen
- php scripts
videofiles
- 1000
- - 24
- - - file.mp4

Config NGINX
server {
listen ip.ip.ip.ip;
root /var/www/domen;
index index.php index.html index.htm;
server_name domen.tv www.domen.tv;
client_max_body_size 2g;

location / {
try_files $uri /index.php;
}

location ~ \.php$ {
access_log /var/log/nginx/access_tv.log;
error_log /var/log/nginx/error_tv.log;

include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}

location ~ \.mp4$ {
root /var/www/videofiles/;
rewrite ^/video/(.+)$ /$1 last;
access_log /var/log/nginx/access_tv_mp4.log;
error_log /var/log/nginx/error_tv_mp4.log;
mp4;
mp4_buffer_size 5m;
mp4_max_buffer_size 10m;
}

location ~ \.flv$ {
root /var/www/videofiles/;
rewrite ^/video/(.+)$ /$1 last;
access_log /var/log/nginx/access_tv_flv.log;
error_log /var/log/nginx/error_tv_flv.log;
flv;
}
}


I used various tricks, but they did not work. Setting up NGINX is not quite a profile for me, so the reason is clearly in my hands.
This article habrahabr.ru/post/151795 was found , but what will happen to the nginx configs for streaming?

I hope I explained everything well, thanks for your attention.

Thanks a lot.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
@
@ntkt, 2013-09-22
_

There is such a module:
wiki.nginx.org/HttpSecureDownload
And another one:
wiki.nginx.org/HttpSecureLinkModule
To use the second one, you will need to write some code that will generate tokens (all this is described in the link).

M
Mikhail Priver, 2013-09-22
@mpriver

Use the X-Accel-Redirect header.
For this location, in which the files are actually located, mark as internal:

location /videofiles {
    root /var/www;
    internal;
}

Such a location will only be available to the user in the case of internal nginx redirects and when using the X-Accel-Redirect header.
To check if a user has access to a file, use the following script:
<?php
    // Здесь проверяете, есть ли у пользователя доступ
    header("X-Accel-Redirect: /videofiles/" . $path);
?>

In this case, all the features provided by direct downloading of static content from the nginx server (for example, resume download) will be available.

T
try4tune, 2013-09-22
@try4tune

Why not make a PHP script that will check the necessary data (IP, etc.), and give the corresponding file through readfile (), for example?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question