Use directive code from other module inside my custom ngx_http_mycontrol_module

Sergey Kandaurov pluknet at nginx.com
Thu Mar 27 11:20:59 UTC 2025


> On 12 Mar 2025, at 19:04, Zyrot System <zyrotnet at gmail.com> wrote:
> 
> Hello everyone, first I want to say I already searched mailman.nginx.org for a topic relating to my question but I cannot find it.
> 
> ngx_http_rewrite_module has directives rewrite, return, etc. I want to use directives code from other module inside my module so can do code reuse "DRY", for example create my own directive like:
> server { # important to work in this Context
> 
> mycontrol * {
> myrewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last; # using the core ngx_http_rewrite_module.c
> 
> }
> mycontrol * {
> # optional using the original ngx_http_rewrite_module.c
> rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last; 
> 
> }
> }
> 
> So can avoid replicate the already functionality (I want to extend the ngx_http_rewrite_module, and others modules in my module mycontrol with more features). Any ideas ?
> I just want to be sure for what route to go, maybe instead I should used the PCRE library directly in ngx_http_mycontrol_module like does other modules ?
> 

Note that in ngx_http_rewrite_module, PCRE API is accessed indirectly,
via ngx_http_script.c / ngx_http_variables.c / ngx_regex.c interfaces
reused with other regex users.
It may depend on your needs on which layer is to reuse the code.

-- 
Sergey Kandaurov


More information about the nginx-devel mailing list