phpnginxdownloadx-sendfile

nginx php x-sendfile download 0kb


I am trying to provide a download with X-Sendfile on my nginx server. I have the most up to date version of nginx, and php5.

The file requested file exists but it just downloads a empty 0kb file, with no content but with the right filename. I dont do any output before the download starts.

At the beginning I had output after the "download" and everything i outputed was readable in the file.

I looked into the nginx docu http://wiki.nginx.org/XSendfile and set the folder which is containing the download file to "internal".


Solution

  • You've confused URI and disk path. You're config should be

    location ^~ /dl/ {
        internal;
        alias /real/path/to/Download/;
    }
    

    I've added modifier ^~ to prevent accidental execution of PHP files in /dl/.