Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I configure the lua_shared_dict to the nginx-kong.conf #4643

Closed
svnshing opened this issue May 22, 2019 · 11 comments
Closed

How can I configure the lua_shared_dict to the nginx-kong.conf #4643

svnshing opened this issue May 22, 2019 · 11 comments

Comments

@svnshing
Copy link

I want to use the lua_shared_dict in my plugin,but I can not add lua_shared_dict profile in the nginx-kong.conf~How can I do it?

@jeremyjpj0916
Copy link
Contributor

jeremyjpj0916 commented May 23, 2019

https://github.com/Kong/kong/blob/master/kong/templates/nginx_kong.lua#L31 All these are the declared shared dictionaries kong has by default. You can add as many as you want in that file prior to starting up Kong.

Not sure if Kong has introduced a parameter in the conf yet to define custom shared memory zones.

@hbagdi
Copy link
Member

hbagdi commented May 23, 2019

You can use Nginx directive injection feature to inject a shared dict into the Nginx conf file of Kong:

nginx_http_lua_shared_dict=my_dict_name 1m

@Ilshidur
Copy link
Contributor

Hello @hbagdi.

Is it possible to inject Nginx directives from a plugin ? Asking because of this.
I am developing a public plugin and I would like to not make the user edit their nginx directives.

I found an ugly workaround using environment variables : export KONG_NGINX_HTTP_LUA_SHARED_DICT="this_dict 20k", but that is still an extra step for the plugin users to do.

BTW, I love your work, guys !

@hbagdi
Copy link
Member

hbagdi commented Jun 3, 2019

I found an ugly workaround using environment variables : export KONG_NGINX_HTTP_LUA_SHARED_DICT="this_dict 20k", but that is still an extra step for the plugin users to do.

@Ilshidur As of today, this is the only way to add a shared dict. Agree that it requires an extra step but should be required only once while setting up configuration for Kong.

I'm going to close this as the original question is answered.
Please re-open if needed.

@hbagdi hbagdi closed this as completed Jun 3, 2019
@nitsshukla-zz
Copy link

nginx_http_lua_shared_dict=my_dict_name 1m

Hi,
How'd one share more than one lua_shared_dict?

@hbagdi
Copy link
Member

hbagdi commented Sep 18, 2019

You can include a file with the include directive, which has a number of shared dicts.

@Darguelles
Copy link

You can set this env var KONG_NGINX_HTTP_LUA_SHARED_DICT: introspection 10m

@Tieske
Copy link
Member

Tieske commented Nov 13, 2020

Adding for reference; recently saw someone add multiple dicts like this;

nginx_http_lua_shared_dict=my_dict_name 1m; lua_shared_dict your_dict_name 1m

EDIT: fixed as correctly identified by @bforbis below

@bforbis
Copy link
Contributor

bforbis commented Mar 15, 2021

@Tieske I am unable to configure kong with multiple shared dicts that way:

My docker-compose:

environment:
  KONG_NGINX_HTTP_LUA_SHARED_DICT: "discovery 1m; jwks 1m; introspection 1m;"

The output I get is:

kong_1     | Error: could not prepare Kong prefix at /usr/local/kong: nginx configuration is invalid (exit code 1):
kong_1     | nginx: [emerg] unknown directive "jwks" in /usr/local/kong/nginx-kong.conf:36
kong_1     | nginx: configuration file /usr/local/kong/nginx.conf test failed

It looks like this env variable will inject the directive into nginx conf as:

lua_shared_dict discovery 1m; jwks 1m; introspection 1m;;

So a hacky workaround to this would be to do the following:

environment:
  KONG_NGINX_HTTP_LUA_SHARED_DICT: "discovery 1m; lua_shared_dict jwks 1m; lua_shared_dict introspection 1m"

which will then generate the following nginx.conf line

lua_shared_dict discovery 1m; lua_shared_dict jwks 1m; lua_shared_dict introspection 1m;

@Tieske
Copy link
Member

Tieske commented Mar 15, 2021

👍 @bforbis thx for the feedback, I updated my post above

@bforbis
Copy link
Contributor

bforbis commented Mar 16, 2021

@Tieske, to be extra clear, you need to add lua_shared_dict directive before each additional shared dict name. The way you have it right now, the generated directive would be:

lua_shared_dict my_dict_name 1m; your_dict_name 1m

This does not compile, since "your_dict_name" is not a known nginx directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants