dongyilu3143 2016-08-21 02:33
浏览 261

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

I'm trying to serve up a protected mp4 file using nginx X-Accel via PHP but I'm having trouble with configuration, as I am getting a 404 error. Here's my nginx.conf server block:

       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;
                }
        }

And here's my php file:

$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);

I'm sure I've just made a simple syntax error, but I can't see it. I have tried adding trailing /s to the location and alias to no avail. Any nginx experts out there?

UPDATE Here's the remainder of my server block:

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制