0

I have a custom nginx module that sets some header to request before proxying request to a server. I also use auth_request for authentication. My location section contains auth_request as well as custom module directive. I want to ensure that the custom header is set only after the auth sub-request and not in the sub-request. Currently I see that the custom module is called first and header is set in the sub request itself.

1 Answer 1

0

There are two ways to order the modules in nginx.

When adding the module handler, it gets added to a phase.

ngx_http_handler_pt *h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
if(h == NULL)
{
    return NGX_ERROR;
}

*h = ngx_dcs_handler;

In this example, we see that the module gets added to the NGX_HTTP_CONTENT_PHASE. I would think that the auth_request gets added in a different earlier phase?

The only other way is to recompile in the correct order. The first module to run is the last on the configure command line.

configure ... --add-module=C --add-module=B --add-module=A

In this case, module A runs first, then B, and finally C.

I'm not too sure whether core modules can as easily be reordered.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.