NGINX perl module to server files
Maxim Dounin
mdounin at mdounin.ru
Mon Sep 2 01:27:48 UTC 2013
Hello!
On Sun, Sep 01, 2013 at 04:29:46PM -0500, Jorge Sanchez wrote:
[...]
> So from above it turns out that there were no headers sent and thus the
> status code probably defaulted to "000" on NGINX.
>
> Adding the send_http_header before the $r->sendfile() solves the issue.
> $r->send_http_header();
Glad to see you've solved your problem with perl code.
BTW, there are some examples at
http://nginx.org/en/docs/http/ngx_http_perl_module.html which may
help.
> 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 ?
The Content-Type nginx set by itself is based on an extension as
seen in URI. As there is no extension in URIs you use, it uses
default type. If a default type isn't what you want - you should
either set response type explicitly, or reconsider URIs used.
In your particular case, I would recommend you to use
$r->internal_redirect() to an internal location instead of trying
to send files yourself. (Or, alternatively, perl_set + rewrite
should also work.) It should be much easier than trying to send
files yourself from perl.
See here for more details:
http://nginx.org/en/docs/http/ngx_http_perl_module.html
--
Maxim Dounin
http://nginx.org/en/donation.html
More information about the nginx
mailing list