# Serving dynamically generated files

**URL:** <https://www.ruby-forum.com/t/serving-dynamically-generated-files/216765>\
**Category:** NGINX\
**Created:** [February 13, 2012, 6:43pm UTC](https://www.ruby-forum.com/t/serving-dynamically-generated-files/216765 "2012-02-13T18:43:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 13, 2012, 6:43pm UTC](https://www.ruby-forum.com/t/serving-dynamically-generated-files/216765/1 "2012-02-13T18:43:32Z")

</div>

Hi everybody,

I’m trying to serve dynamically generated TXT files using PHP through  
fastcgi\_pass, but I have a problem that I can’t solve.  
This is what I have done:

- The TXT files are going to be used by a “GPRS printer” that read  
them  
from an url (ex: [http://server/1234.txt](http://server/1234.txt))
- I have configured Nginx to rewrite the request of this files to a  
PHP  
script
- The PHP script returns the TXT contents and the same headers as for  
an  
static TXT file
- If a load the URL on a browser, the content and the headers are  
fine.  
In fact, if I create the static TXT file with the same content of the  
PHP  
generated, my browser shows me exactly the same.

My problem is that the “printer” is not reading the TXT file correctly.  
I know that the “printer” is working, because of two things:

- If a create the static 1234.txt file, the “printer” prints it  
correctly
- When the printer reads the dynamically generated TXT file, the PHP  
scripts also sends me an email, so I’m sure that the printer is  
connecting  
to the URL.

So, my question is… is there any difference of how Nginx serves static  
files towards dynamically generated ones?

I’ve researched through internet and I cannot find an answer ☹

Thanks in advance!  
Gregorio

---

<div class="post-metadata">

**Author:** ![SSGregorio\_HernSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@SSGregorio\_HernSSnd](https://www.ruby-forum.com/u/SSGregorio_HernSSnd)\
**Post date:** [February 14, 2012, 12:07pm UTC](https://www.ruby-forum.com/t/serving-dynamically-generated-files/216765/2 "2012-02-14T12:07:36Z")

</div>

13 февраля 2012, 21:42 от Gregorio Hernández Caso : \> Hi everybody, \> \>  
I’m trying to serve dynamically generated TXT files using PHP through \>  
fastcgi\_pass, but I have a problem that I can’t solve. \> This is what I  
have done: \> \> - The TXT files are going to be used by a “GPRS printer”  
that read them \> from an url (ex: [http://server/1234.txt](http://server/1234.txt)) \> - I have  
configured Nginx to rewrite the request of this files to a PHP \> script

> - The PHP script returns the TXT contents and the same headers as for  
> an \> static TXT file \> - If a load the URL on a browser, the content and  
> the headers are fine. \> In fact, if I create the static TXT file with  
> the same content of the PHP \> generated, my browser shows me exactly the  
> same. \> \> My problem is that the “printer” is not reading the TXT file  
> correctly. \> I know that the “printer” is working, because of two  
> things: \> \> - If a create the static 1234.txt file, the “printer” prints  
> it correctly \> - When the printer reads the dynamically generated TXT  
> file, the PHP \> scripts also sends me an email, so I’m sure that the  
> printer is connecting \> to the URL. \> \> So, my question is… ¿is there  
> any difference of how Nginx serves static \> files towards dynamically  
> generated ones? \> \> I’ve researched through internet and I cannot find  
> an answer ☹ First run “curl -v [http://server/1234.txt](http://server/1234.txt)” to make sure  
> your PHP script is generating correct headers - in this case you should  
> be sending “Content-Type: text/plain\r\n\r\n” before the actual content.  
> A missing Content-Length header could also cause problems. Next, either  
> enable debug level logging in nginx: error\_log /var/log/nginx.error.log  
> debug; or just use “nc -v -l 8080” on your server and have your “GPRS  
> printer” connect to [http://server:8080/1234.txt](http://server:8080/1234.txt) so you can check its  
> request headers. Max
