mdounin at mdounin.ru
Thu May 17 13:11:45 UTC 2018
On Wed, May 16, 2018 at 01:05:50PM -0700, Dk Jack wrote:
> Hi Maxim,
> I am sending the response in the request handler which I registered for
> in the NGX_HTTP_SERVER_REWRITE_PHASE handler. In my handler, I have the
In a rewrite phase handler you are _not_ expected to return a
response. If you do return it, you have to be careful to properly
cancel additional request processing.
Moreover, the server rewrite phase is _not_ executed for
locations. Instead, it is a phase for rewrites affecting the
whole server block. The configuration example you've provided
makes no sense for a module which works in the server rewrite
For returning a custom response in a specifically set location it
might be better idea to use the content phase, or, even simplier,
to register a location-specific content handler. See empty gif
module sources for a relatively simple example.
> following code to avoid responding multiple times as well. Still, I am getting
> the error.
> if (r->main->count > 1)
> return NGX_DECLINED;
This is not expected to prevent anything from being executed
multiple times. Rather, it will prevent your code from executing
when there is more than one reference to the request.
You may want to read some guides on writing nginx modules, as it
is more or less clear you don't understand basics. In particular,
Evan Miller's one might be a good start:
Refer to the Development Guide for more advanced subjects:
More information about the nginx-devel