I have next problem with nginx. I setted up code to serve secured files. This is PHP code that redirects request:
$file_path = '';
$start = (isSet($_GET['start']) ? '?start='.$_GET['start'] : '');
if(check_url($org_url)){
header("X-Accel-Redirect: /film/".$file_path.$start); die();
}
else {
header("Location: /403.html");
die();
}
and check_url function:
function check_url($org_url){
global $file_path;
...
$file_path = $_GET['file'];
...
$hash = md5(...);
if($url_time_to > time() && $hash === $url_hash){ return true; }
else return false;
}
Then I have such nginx config:
location /file/ {
rewrite . /file.php last;
}
location /file.php {
internal;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /film {
alias /var/www/filmy;
mp4;
flv;
internal;
}
and it all works. But I tried better (for me) config, where I can set separate directories inside config for different file types:
location /file/ {
rewrite . /file.php last;
}
location /file.php {
internal;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /film/.*\.flv$ {
internal;
alias /var/www/filmy;
flv;
}
location ~ /film/.*\.mp4$ {
internal;
alias /var/www/filmy;
mp4;
Request to http://unexisting.com/file/....../54agda0g8.flv redirects me to http://unexisting.com/film/54agda0g8.flv/
God why? If you need live example let me know.
Nginx documentation says:
So you need to have captures in regexp, like this:
BTW, why do you want to split this config?