Interaction between ngx module and fastcgi program
mdounin at mdounin.ru
Mon Jan 14 16:47:55 UTC 2019
On Mon, Jan 14, 2019 at 08:33:23AM -0800, Mark Sellers wrote:
> Thanks for your great feedback. It is truly appreciated.
> I am finalizing a simple nginx module, that does a uri rewrite. I have tested it, and the rewrite is working fine for files that exist on the server.
> A second component of my system is a fastcgi program (written in C) that, upon execution using the try_files named location. This fastcgi program has been tested, and works fine, by itself.
> My problem comes when both the module and fastcgi program are working together. Something in the combined environment is causing a malfunction.
> Could you please take a look at the annotated debug outputs, and suggest an approach to find the issue, and fix it? Please refer to below and see my notes offset to the left of the listing:
> Debug log with module and fastcgi both operating (I removed the first two columns of the debut output to provide a better fit on this page:
> [debug] 20594#0: *1 event timer del: 19: 556031347
> [debug] 20594#0: *1 rewrite phase: 0
> [debug] 20594#0: *1 test location: "/"
> [debug] 20594#0: *1 test location: "images/"
> [debug] 20594#0: *1 using configuration "/images/"
> [debug] 20594#0: *1 http cl:-1 max:104857600
> [debug] 20594#0: *1 rewrite phase: 2
> [debug] 20594#0: *1 fastimg handler <- My module
> [debug] 20594#0: *1 ngx_http_fastimg_rewrite() uri in: "/images/12/255/0/0.jpg” <- Input uri
> [debug] 20594#0: *1 ngx_http_fastimg_rewrite() uri out: "/images/21/12_255_0_0.jpg” <- Output uri (rewritten)
> [debug] 20594#0: *1 internal redirect: "/images/21/12_255_0_0.jpg?” <- Internal redirect using ngx_http_internal_redirect(r, &uri, NULL)
> [debug] 20594#0: timer delta: 1
> [debug] 20594#0: worker cycle
> [debug] 20594#0: epoll timer: 60000
> [debug] 20594#0: epoll: fd:20 ev:0005 d:0000000000D4E5B8
> [debug] 20594#0: *1 http upstream request: "0100101 Firefox/�D <- SOMETHING IS BROKE!!
> [debug] 20594#0: *1 http upstream process header
Check how do you allocate URI as passed to the
ngx_http_internal_redirect() function. I suspect you are using
stack or other temporary allocated buffer there, and this is what
causes the problem: as long as the buffer is overwritten,
everything is broken. Instead, you should allocate the URI string
as passed to ngx_http_internal_redirect() from the request memory
pool, so it will not be rewritten till the request is freed.
More information about the nginx-devel