ingress-nginx-helm/rootfs/etc/nginx/lua/plugins/README.md
Josh Soref c6a8ad9a65
Darwin arm64 (#8399)
* Use sed instead of gnu find flags

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Support building linux/amd64 on darin/arm64

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Upgrade awesome_bot to dkhamsing/awesome_bot:1.20.0

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Favor find -prune for vendor

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Skip golang modcache folder

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Favor find -prune for changelog

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Ignore Changelogs of any case

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Fix service-l7 link

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Fix route53-mapper link

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Update rootfs contents description

The auxiliary scripts were removed after:
ab8349008a/rootfs/ingress-controller

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Update paths for modsecurity

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Update paths for modsecurity_snippet

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Update toc for 20190815-zone-aware-routing.md

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Use Internet Archive for datapath.io blog entry

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Use Internet Archive for cloudflare.com help center entry

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Use https for nginx.org

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-06 13:46:26 -07:00

2.5 KiB

Custom Lua plugins

ingress-nginx uses https://github.com/openresty/lua-nginx-module to run custom Lua code within Nginx workers. It is recommended to familiarize yourself with that ecosystem before deploying your custom Lua based ingress-nginx plugin.

Writing a plugin

Every ingress-nginx Lua plugin is expected to have main.lua file and all of its dependencies. main.lua is the entry point of the plugin. The plugin manager uses convention over configuration strategy and automatically runs functions defined in main.lua in the corresponding Nginx phase based on their name.

Nginx has different request processing phases. By defining functions with the following names, you can run your custom Lua code in the corresponding Nginx phase:

  • init_worker: useful for initializing some data per Nginx worker process
  • rewrite: useful for modifying request, changing headers, redirection, dropping request, doing authentication etc
  • header_filter: this is called when backend response header is received, it is useful for modifying response headers
  • body_filter: this is called when response body is received, it is useful for logging response body
  • log: this is called when request processing is completed and a response is delivered to the client

Check this hello_world plugin as a simple example or refer to OpenID Connect integration for more advanced usage.

Do not forget to write tests for your plugin.

Installing a plugin

There are two options:

  • mount your plugin into /etc/nginx/lua/plugins/<your plugin name> in the ingress-nginx pod
  • build your own ingress-nginx image like it is done in the example and install your plugin during image build

Mounting is the quickest option.

Enabling plugins

Once your plugin is ready you need to use plugins configuration setting to activate it. Let's say you want to activate hello_world and open_idc plugins, then you set plugins setting to "hello_world, open_idc". Note that the plugins will be executed in the given order.