Hey,<div><br></div><div>Try adding this to your nginx conf where applicable:</div><div><br></div><div><font face="courier new, monospace">add_header Content-Disposition attachment;</font></div><span style="border-collapse:collapse;font-size:13px"><div>
<span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px"><br></span></div><div style="font-family:arial,sans-serif"><span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px">Reg</span>ards,</div>
<div style="font-family:arial,sans-serif"><br></div><a href="http://www.twitter.com/jdorfman" target="_blank" style="font-family:arial,sans-serif">Justin Dorfman</a><br><br><a href="http://www.netdna.com" target="_blank" style="font-family:arial,sans-serif">NetDNA</a><font face="arial, sans-serif">™</font><br>
<font face="arial, sans-serif">The Science of Acceleration™</font><br></span><br>
<br><br><div class="gmail_quote">On Mon, Aug 27, 2012 at 6:29 PM, wideawake <span dir="ltr"><<a href="mailto:nginx-forum@nginx.us" target="_blank">nginx-forum@nginx.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a script that uses x-accel-redirect on a nginx server to send large<br>
files (150mb+). The script serves downloads fine as long as their is a space<br>
in the name of the directory but not when the directory is a single word.<br>
Anyone know why it would be doing so when the file exists and the path is<br>
correct?<br>
<br>
Layout: /Dir/file.exe /Dir2/file.exe /Another Dir/file.exe<br>
<br>
If it's /Another Dir/file.exe it serves the file perfectly, however if its<br>
/Dir/file.exe it serves the html of the download page. Anyone seen this<br>
before?<br>
<br>
nginx config:<br>
server {<br>
  access_log  logs/access_log;<br>
  access_log  on;<br>
  limit_conn  gulag 3;<br>
  error_log  /var/log/nginx/vhost-error_log crit;<br>
  listen    80 default;<br>
  server_name  <a href="http://www.my.com" target="_blank">www.my.com</a> <a href="http://my.com" target="_blank">my.com</a>;<br>
  root   /home/mysite/public_html;<br>
  #root /usr/share/nginx/html;<br>
  autoindex off;<br>
  index  index.php index.html index.htm;<br>
<br>
<br>
<br>
  #rewrite ^.*/([-\w\.]+)/([-\w\.]+)\.zip$<br>
/download.php?model=$1&file=$2.zip last;<br>
  #rewrite ^.*/([-\w\.]+)/([-\w\.]+)\.exe$<br>
/download.php?model=$1&file=$2.exe last;<br>
  #rewrite ^.*/([-\w\.]+)/([-\w\.]+)\.nbh$<br>
/download.php?model=$1&file=$2.nbh last;<br>
  #rewrite ^.*/([-\w\.]+)/([-\w\.]+)\.rar$<br>
/download.php?model=$1&file=$2.rar last;<br>
<br>
  error_page 503 /503.html;<br>
        location = /503.html {<br>
        root /home/mysite/public_html/errors;<br>
        }<br>
<br>
<br>
  error_page 504 /504.html;<br>
        location = /504.html {<br>
        root /home/mysite/public_html/errors;<br>
        }<br>
<br>
<br>
  # pass the PHP scripts to FastCGI server<br>
        location ~ \.php$ {<br>
            fastcgi_pass   <a href="http://127.0.0.1:8888" target="_blank">127.0.0.1:8888</a>;<br>
             #fastcgi_pass    unix:/var/run/nginx-fcgi.sock;<br>
            fastcgi_index  index.php;<br>
            fastcgi_param  SCRIPT_FILENAME<br>
/home/mysite/public_html$fastcgi_script_name;<br>
            include        /etc/nginx/fastcgi_params;<br>
<br>
             fastcgi_intercept_errors off;<br>
        }<br>
<br>
<br>
 }<br>
<br>
php code:<br>
<?php<br>
/*File Download Script*/<br>
$fileserver_path = "./shipped/";        // change this to the directory your files<br>
reside<br>
$fileurlpath = "<a href="http://my.com/shipped/" target="_blank">http://my.com/shipped/</a>";<br>
$req_file                = basename($_GET['file']);<br>
$model                   = $_GET['model'];<br>
$thisfile                        = basename(__FILE__);<br>
$msg="";<br>
$error=FALSE;<br>
<br>
$path = $model."/".$req_file;<br>
<br>
<br>
if (empty($req_file)) {<br>
        $error=TRUE;<br>
        $msg .= "Usage: $thisfile?model=&lt;model<br>
name&gt;&amp;file=&lt;file_to_download&gt;<br />";<br>
}<br>
<br>
if (! isset($_GET["model"])) {<br>
        $error=TRUE;<br>
        $msg .= "No Model information present. Unable to continue.<br />";<br>
} else {<br>
        $fileserver_path .= $model."/";<br>
        $fileurlpath .= $model."/";<br>
        /* check if file exists */<br>
        if (!file_exists($fileserver_path.$req_file)) {<br>
                $error=TRUE;<br>
                $msg .= "$req_file doesn't exist.";<br>
        }<br>
}<br>
<br>
/* no web spamming */<br>
if (!preg_match("/^[a-zA-Z0-9._-]+$/", $req_file, $matches)) {<br>
        $error=TRUE;<br>
        $msg .= "Spamming! I can't do that. Sorry.";<br>
}<br>
<br>
if(! ($error)) {<br>
//Hotlink Code<br>
if(eregi($_SERVER["HTTP_HOST"], str_replace("www.", "",<br>
strtolower($_SERVER["HTTP_REFERER"]))))<br>
{<br>
        if (! isset($_GET['send_file'])) {<br>
<br>
                Header("Refresh: 5;<br>
url=<a href="http://my.com/$thisfile?model=$model&file=$req_file&send_file=yes" target="_blank">http://my.com/$thisfile?model=$model&file=$req_file&send_file=yes</a>");<br>
<br>
        }<br>
        else {<br>
<br>
                header("Cache-Control: public");<br>
                header('Content-Description: File Transfer');<br>
                header("Content-type: application/octet-stream");<br>
                //header('Content-Type: application/force-download');<br>
                //header('Content-Length: ' . filesize($fileserver_path.$req_file));<br>
                header('Content-Disposition: attachment; filename=' . $req_file);<br>
                header("Content-Transfer-Encoding: binary");<br>
                header("X-Accel-Redirect: /shipped/" . $path);<br>
<br>
                exit;<br>
<br>
        }<br>
//More Hotlink Code<br>
 } else {<br>
        Header("Refresh: ;<br>
url=<a href="http://my.com/$thisfile?model=$model&file=$req_file" target="_blank">http://my.com/$thisfile?model=$model&file=$req_file</a>");<br>
 }<br>
//End Hotlink<br>
}<br>
?><br>
<br>
Posted at Nginx Forum: <a href="http://forum.nginx.org/read.php?2,230161,230161#msg-230161" target="_blank">http://forum.nginx.org/read.php?2,230161,230161#msg-230161</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br>