nginx X-Accel-Redirect通过PHP,404错误

时间:2016-08-21 02:33:07

标签: php nginx mp4 x-accel-redirect

我试图通过PHP使用nginx X-Accel来提供受保护的mp4文件,但我遇到配置问题,因为我收到404错误。这是我的nginx.conf服务器块:

       server {
                listen       80;
                server_name  localhost;
                root /var/www/example.com;

                location / {
                        try_files $uri /index.php?$args;
                }
                location /protected {
                        internal;
                        alias /var/www/uploads;
                }
        }

这是我的php文件:

$aliasedFile = '/protected/' . $filename; //this is the nginx alias of the file path
$realFile = "/var/www/uploads/" . $filename; //this is the physical file path
header('Cache-Control: public, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: video/mp4');
header('Content-Length: ' .(string)(filesize($realFile)) );
header('Content-Transfer-Encoding: binary');
header('X-Accel-Redirect: ' . $aliasedFile);

我确定我发出了一个简单的语法错误,但我无法看到它。我尝试将尾随/添加到该位置并使用别名无效。那里有任何nginx专家吗?

更新这是我的服务器块的其余部分:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/example.com;
    index index.php index.html index.htm;

    server_name server_domain_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

0 个答案:

没有答案