Welcome! Log In Create A New Profile

Advanced

Re: Interaction between ngx module and fastcgi program

Maxim Dounin
January 14, 2019 11:48AM
Hello!

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.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Interaction between ngx module and fastcgi program

Mark Sellers 352 January 14, 2019 11:34AM

Re: Interaction between ngx module and fastcgi program

Maxim Dounin 145 January 14, 2019 11:48AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 305
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready