About the order of execution of the modules.
francis at daoine.org
Mon Mar 15 17:25:56 UTC 2021
On Mon, Mar 15, 2021 at 06:49:44AM +0000, ADD SP wrote:
> > It is not clear to me that that "so" statement is true.
> I made a stupid mistake. I didn't recompile nginx and my modules when I debugged with GDB, so I thought that "ngx_module_order" wouldn't solve my problem, but when I retested it I found that "ngx_module_order " solved my problem. Thank you.
Good that you found a thing that works :-)
As with most things software, there is "what is documented as the API
that is intended to work in the future", and there is "the current
If you can't find a "here is the recipe to ensure that your module always
executes in *this* position in the list" document, that might be because
the product does not intend to make guarantees that that method will
remain working in the future.
So whatever is there today, should work today; and if the execution
order matters to you, then you will have to test after any update to
see whether things still work for you.
I suspect that, in the main, you are not expected to care about the full
module order. But the source is there, and nothing stops you from changing
it to work the way you want it to work. (At least: in your build.)
> Here are some minor issues I would like to discuss with you.
> > My reading suggests that the "static" module order is "from the
> ... /configure line, --add-module order", and the "dynamic" module order is
> "from the nginx.conf file, load_module order", where the dynamic modules
> have the option to list which named modules they should run before.
> Is the order of execution of dynamic modules determined by the "load_module" order? Where did you find this? I looked at http://nginx.org/en/docs/ngx_core_module.html#load_module but did not find this statement.
Probably the simplest thing at this stage is just to point you at the
implementation -- that is exactly what the current version of nginx does,
and any attempted explanations that contradict it are wrong.
auto/module sets the shell variable [this_module]_ORDER; auto/make reads
that and populates the C variable "char *ngx_module_order" for this
module; and src/core/nginx.c says what happens when a load_module directive
is read from nginx.conf, which includes reading ngx_module_order and
calling ngx_add_module() from src/core/ngx_module.c
> > As the developer, I think that you do not know which stock modules are
> But you do know the names of the (current) stock modules.
> It seems that some of the stock modules (standard modules) can also be compiled as dynamic modules, e.g. " --with-stream=dynamic", so perhaps I have misunderstood something.
The person building nginx can choose (with some limitations) which
standard modules are included as static; which third-party modules are
included as static and in what order; and (sort of) whether dynamic
modules can be usefully used.
If dynamic modules can be used, then the person configuring nginx can
choose which standard-or-third-party dynamic modules are loaded, and in
> > You will be "after", unless you set your ngx_module_order.
> I found out through GDB debugging that my module takes effect before "ngx_http_rewrite_module" if I don't set "ngx_module_order". Perhaps third party dynamic modules are executed before the stock (standard) modules?
Yes, I was probably unclear/misleading on that, sorry.
There is the order of loading the modules, and there is the order of
running of modules, and they are backwards with respect to each other. I
was intending to use before/after in the "loading" sense, so, unless I
got confused somewhere, please reconsider my mail in that light.
Francis Daly francis at daoine.org
More information about the nginx