Streaming dynamic downloads?

I have a php app running through fastcgi, and there’s a page where I
stream out a file for the user to download:

$output = dynamically_generated_content();
header(“Content-type: application/octet-stream”);
header(“Content-disposition: attachment; filename=somefile.xml”);
echo $output;

This works fine in apache, but in nginx all I get is a zero-size file
called ‘somefile’ (no extension)

Is there a way to make this work? The file is generated on the fly.

Thanks,
Jeff

[SOLVED]

On Sat, May 17, 2008 at 10:23 PM, jeff emminger [email protected]
wrote:

Is there a way to make this work? The file is generated on the fly.

Thanks,
Jeff

Turned out to be a problem with the URL I was using. I was pointing
to “/export?xml” (no trailing slash), and Nginx was redirecting to
“/export/” (with trailing slash) but dropping the querystring. I
changed my link to point to “/export/?xml” and all is well. The
zero-kb file download was a result of my script expecting the file
format in the querystring, and not finding the format it generated
nothing and sent back the empty file.

On Sat, May 17, 2008 at 11:34:17PM -0400, jeff emminger wrote:

to “/export?xml” (no trailing slash), and Nginx was redirecting to
“/export/” (with trailing slash) but dropping the querystring. I
changed my link to point to “/export/?xml” and all is well. The
zero-kb file download was a result of my script expecting the file
format in the querystring, and not finding the format it generated
nothing and sent back the empty file.

What nginx version do you use ? This bug (dropping the querystring) has
been fixed in 0.6.8 and 0.5.32.

What nginx version do you use ? This bug (dropping the querystring) has
been fixed in 0.6.8 and 0.5.32.

[admin@secure ~]$ /usr/local/nginx/sbin/nginx -v
nginx version: nginx/0.5.35

On Sun, May 18, 2008 at 10:27:55AM -0400, jeff emminger wrote:

What nginx version do you use ? This bug (dropping the querystring) has
been fixed in 0.6.8 and 0.5.32.

[admin@secure ~]$ /usr/local/nginx/sbin/nginx -v
nginx version: nginx/0.5.35

Could you show your configuraiton of “/export/” ?

Could you show your configuraiton of “/export/” ?

Hi Igor,

I haven’t explicitly configured ‘/export/’, it is just a subdirectory
of the application configured at:

server {
listen 443;

ssl on;
ssl_certificate /etc/ssl/certs/secure.mysite.org.crt;
ssl_certificate_key /etc/ssl/private/secure.mysite.org.key;

server_name secure.mysite.org;

access_log logs/mysite.org.access.log main;

location / {
root /var/www/docs/mysite.org/secure;
index index.html index.htm index.php;
}

error_page 404 /404.html;

redirect server error pages to the static page /50x.html

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/var/www/docs/mysite.org/secure/$fastcgi_script_name;
include conf/fastcgi.conf;
}

deny access to .htaccess files, if Apache’s document root

concurs with nginx’s one

location ~ /.ht {
deny all;
}
}

On Mon, May 19, 2008 at 07:00:45PM +0400, Igor S. wrote:

Then this is application bug.
Sorry, this is nginx bug, it should return correct redirect for static
directories.

On Mon, May 19, 2008 at 10:42:15AM -0400, jeff emminger wrote:

Could you show your configuraiton of “/export/” ?

Hi Igor,

I haven’t explicitly configured ‘/export/’, it is just a subdirectory
of the application configured at:

Then this is application bug.

nginx return redirect for “/export” for following location:

 location /export/ {
     proxy_pass    ...
     or
     fastcgi_pass  ...
 }

Then this is application bug.

Sorry, this is nginx bug, it should return correct redirect for static
directories.

No problem, easy enough to add the trailing slash to my link for now.
Thanks for checking into it!
-Jeff