Welcome! Log In Create A New Profile

Advanced

Re: X-accel-redirect serving html download page instead of file.

Justin Dorfman
August 27, 2012 09:58PM
Hey,

Try adding this to your nginx conf where applicable:

add_header Content-Disposition attachment;

Regards,

Justin Dorfman http://www.twitter.com/jdorfman

NetDNA http://www.netdna.com™
The Science of Acceleration™



On Mon, Aug 27, 2012 at 6:29 PM, wideawake <nginx-forum@nginx.us> wrote:

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

X-accel-redirect serving html download page instead of file.

wideawake August 27, 2012 09:29PM

Re: X-accel-redirect serving html download page instead of file.

Justin Dorfman August 27, 2012 09:58PM

Re: X-accel-redirect serving html download page instead of file.

wideawake August 27, 2012 10:05PM

Re: X-accel-redirect serving html download page instead of file.

Justin Dorfman August 27, 2012 10:32PM

Re: X-accel-redirect serving html download page instead of file.

wideawake August 27, 2012 11:02PM

Re: X-accel-redirect serving html download page instead of file.

Maxim Dounin September 03, 2012 02:32PM

Re: X-accel-redirect serving html download page instead of file.

poulphunter December 04, 2012 09:07AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 270
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready