# How to control the order of execution modules in nginx

**URL:** <https://www.ruby-forum.com/t/how-to-control-the-order-of-execution-modules-in-nginx/238819>\
**Category:** NGINX\
**Created:** [January 30, 2014, 6:06am UTC](https://www.ruby-forum.com/t/how-to-control-the-order-of-execution-modules-in-nginx/238819 "2014-01-30T06:06:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [January 30, 2014, 6:06am UTC](https://www.ruby-forum.com/t/how-to-control-the-order-of-execution-modules-in-nginx/238819/1 "2014-01-30T06:06:06Z")

</div>

Fromhttp://www.evanmiller.org/nginx-modules-guide.html, “The order of  
their execution is determined at compile-time”. Is there a way to  
control this. ngx\_modules.c has the list and order of execution. How do  
I change the order of execution of modules within a particular phase  
e.g. if I have three modules within the access phase, is there a way to  
control the order of execution with the access phase.

---

<div class="post-metadata">

**Author:** ![Rv\_Rv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c0e974/32.png) [@Rv\_Rv](https://www.ruby-forum.com/u/Rv_Rv)\
**Post date:** [January 30, 2014, 1:09pm UTC](https://www.ruby-forum.com/t/how-to-control-the-order-of-execution-modules-in-nginx/238819/2 "2014-01-30T13:09:15Z")

</div>

Hello!

On Thu, Jan 30, 2014 at 01:05:34PM +0800, Rv Rv wrote:

> Fromhttp://www.evanmiller.org/nginx-modules-guide.html, “The  
> order of their execution is determined at compile-time”. Is  
> there a way to control this. ngx\_modules.c has the list and  
> order of execution. How do I change the order of execution of  
> modules within a particular phase e.g. if I have three modules  
> within the access phase, is there a way to control the order of  
> execution with the access phase.

Order of execution of modules in a particular phase is set during  
a configure, modules which are last in HTTP\_MODULES are executed  
first.

That is, if you want to add “module1”, “module2”, and “module3”,  
all of them use the access phase, and each of them does something  
like

```
HTTP_MODULES="$HTTP_MODULES moduleN"

```

in it’s “config” file, you should do something like

```
./configure --add-module=module3 \
            --add-module=module2 \
            --add-module=module1

```

to get the “module1 → module2 → module3” order.

Note that it may non-trivial to, e.g., make sure your module is  
called after standard modules in the access phase.

–  
Maxim D.  
[http://nginx.org/](http://nginx.org/)
