<div dir="ltr"><div><div><div><div>Hello list,<br><br></div>here is the strace of the NGINX serving my media file (Jpg) to the client:<br><br></div>Accepting the connection:<br><br><font face="courier new,monospace">25003 accept4(6, {sa_family=AF_INET, sin_port=htons(53907), sin_addr=inet_addr("XXX.XXX.XXX.XX")}, [16], SOCK_NONBLOCK) = 3<br>
<br><font face="arial,helvetica,sans-serif">Opening the file:</font><br>25003 open("/usr/site/gruppe/media/t_pics/images/thumbs/714.jpg", O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 15<br>25003 fstat64(15, {st_mode=S_IFREG|0755, st_size=5420, ...}) = 0<br>
<br><font face="arial,helvetica,sans-serif">Sending the file to the client with sendfile:</font><br>25003 sendfile64(3, 15, [0], 5420)      = 5420<br><br><br></font></div><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">So from above it turns out that there were no headers sent and thus the status code probably defaulted to "000" on NGINX<font face="courier new,monospace">.<br>
<br></font></font></font></div><div><font face="courier new,monospace"><font face="arial,helvetica,sans-serif"><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">Adding the send_http_header before the $r->sendfile() solves the issue.<br>
<span style="font-family:courier new,monospace">$r->send_http_header();</span><br></font></font></font></font></div><div><font face="courier new,monospace"><font face="arial,helvetica,sans-serif"><font face="courier new,monospace"><br>
<font face="arial,helvetica,sans-serif">Now I have the correct HTTP status code, anyway the content type defaults to "application/octet-stream" which is configured as default content type on nginx. Well, is there a way to have NGINX correctly set the Content-Type after handling the request on perl content handler or should I make my own mapping and set the content-type myself in send_http_header ? <br>
<br></font></font></font></font><span style="color:rgb(0,0,127);font-family:courier;font-size:13px;font-style:normal;font-variant:normal;font-weight:300;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(237,237,251);display:inline!important;float:none">HTTP/1.1 200 OK
Server: nginx/1.5.5
Date: Sun, 01 Sep 2013 21:17:41 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive</span><br><br><br></div><div>Regards,<br><br>Jorge<br></div><font face="courier new,monospace"></font></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Aug 31, 2013 at 4:46 PM, Jorge Sanchez <span dir="ltr"><<a href="mailto:xsanch@gmail.com" target="_blank">xsanch@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hello,<br><br></div>I have created  perl NGINX module to server static files on the NGINX (mainly images). For security reasons I am generating the AES:CBC encrypted url which I am decrypting on the NGINX and serving the file via NGINX perl module. The problem is that I am sometimes getting the bellow response with HTTP response code set to 000:<br>


<br><br><font face="courier new,monospace">XX.XX.XX.XX - - [01/Sep/2013:01:20:37 +0400] "GET /media/u5OU/NRkImrrwH/TThHe7hns5bOEv+Aou2/VJ8YD/ts= HTTP/1.1" <span style="color:rgb(255,0,0)"><b><u>000</u></b></span> 39078 "<a href="http://gruppu.com/full/JcbyEJTb8nMh+YH0xSg1jgl4N7vWQi2xBPep7VcJmD8=" target="_blank">http://XXXX/full/JcbyEJTb8nMh+YH0xSg1jgl4N7vWQi2xBPep7VcJmD8=</a>" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0"<br>


<br><br></font></div><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">The way how I handle the url in the perl module is :<br><br><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">In case the file is found:</font><br>

$r->sendfile($fileresult[0]);<br>$r->flush();</font><br></font></font></div><font face="courier new,monospace"><font face="arial,helvetica,sans-serif"></font></font><div>
<div><font face="courier new,monospace">return OK;<br><br></font></div><div><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">else:<span style="font-family:courier new,monospace"><br>$r->status(404);<br>

return DECLINED;</span><br></font></font></div><div><font face="courier new,monospace"><br><br></font></div><div><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">My question is if I am sending the files correctly or is there any other specific value i should send back from perl (besides returning OK). <br>

<br>If needed I can send the nginx.conf. <br><br><br>Thanks for your help. <br><br>Regards,<br><br><br>Jorge<br></font></font></div></div></div>
</blockquote></div><br></div>