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

support include other nginx config in the apisix(lua file) #2565

Closed
nanamikon opened this issue Oct 29, 2020 · 10 comments · Fixed by #2803
Closed

support include other nginx config in the apisix(lua file) #2565

nanamikon opened this issue Oct 29, 2020 · 10 comments · Fixed by #2803
Milestone

Comments

@nanamikon
Copy link
Contributor

Issue description

I can find that apisix use template to generate nginx.conf in the apisix(lua file), we need to change this file in following scenarios in my company

  • Setting third nginx module param;
  • Setting nginx params not supported in config.ymal
  • Export other servers and locations which third nginx module needed

What's about adding a new feature, for example, support including other nginx conf file in the apisix(lua file)
Thank you!

Environment

  • apisix version (master):
@nic-chen
Copy link
Member

nic-chen commented Oct 30, 2020

Could you please show some example?

@nanamikon
Copy link
Contributor Author

nanamikon commented Oct 30, 2020

Sure!
For example

Third-party nginx module param

req_status_zone host "$server_name" 200M;
req_status_zone hostadr "$server_name:$upstream_addr" 200M;
req_status host hostadr;
req_status_lazy on;

server
{
    listen 45651;
    server_name _;
    access_log off;

    location /ysec_status {
        req_status_show;
        allow 127.0.0.1;
        deny all;
    }
}

Other not support nginx param

gzip             on;
gzip_comp_level  6;
gzip_min_length  1k;
gzip_buffers     4 8k;
gzip_disable     "MSIE [1-6]\.(?!.*SV1)";
gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/javascript application/json;

@tzssangglass
Copy link
Member

You mean like the nginx_http_include directive from kong?

nginx_http_include = /path/to/your/extend.conf

the extend.conf may be like

lua_shared_dict custom_plugin_a_cache 8m;
lua_shared_dict custom_plugin_b_cache 8m;

then this configuration will appear in the nginx.conf

@spacewander
Copy link
Member

I will vote for ingress-nginx's snippet feature:
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet

This feature can be configured directly in the yaml file.

@nic-chen
Copy link
Member

I will vote for ingress-nginx's snippet feature:

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet

This feature can be configured directly in the yaml file.

agree +1

@tzssangglass
Copy link
Member

I doubt this will solve the renaming configuration, e.g. I want to configure multiple lua_shared_dict

@spacewander
Copy link
Member

@tzssangglass
Configure lua_shared_dict is already supported:

#lua_shared_dicts: # add custom shared cache to nginx.conf

Why do you think this feature can't be supported via snippets?

@moonming moonming added this to the 2.1 milestone Oct 30, 2020
@tzssangglass
Copy link
Member

@tzssangglass
Configure lua_shared_dict is already supported:

#lua_shared_dicts: # add custom shared cache to nginx.conf

Why do you think this feature can't be supported via snippets?

Good. I had misconceptions about snippets before. I'm not sure if all the configurations can be translated from yaml to the final nginx.conf, so I thought if the ability to load extend.conf could be provided, there could be a back up plan.

@nanamikon
Copy link
Contributor Author

I will vote for ingress-nginx's snippet feature:
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet

This feature can be configured directly in the yaml file.

Good idea , most of situation can be covered。

server
{
    listen 45651;
    server_name _;
    access_log off;

    location /ysec_status {
        req_status_show;
        allow 127.0.0.1;
        deny all;
    }
}

But I think this format of config is not suitable to write to ymal

@spacewander
Copy link
Member

@nanamikon
I think we can write them in a literal block, see literal_block in https://learnxinyminutes.com/docs/yaml/. We should take care about the indentation of Nginx configuration. But once the configuration is indented, it is suitable in the yaml file.

@membphis membphis modified the milestones: 2.1, 2.2 Nov 15, 2020
spacewander added a commit to spacewander/incubator-apisix that referenced this issue Nov 20, 2020
spacewander added a commit that referenced this issue Nov 25, 2020
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

Successfully merging a pull request may close this issue.

6 participants