Customize Nginx configuration

The Nginx configuration used by APISIX is generated via the template file apisix/cli/ngx_tpl.lua and the options from conf/config-default.yaml / conf/config.yaml.

You can take a look at the generated Nginx configuration in conf/nginx.conf after running ./bin/apisix start.

If you want to customize the Nginx configuration, please read through the nginx_config in conf/config-default.yaml. You can override the default value in the conf/config.yaml. For instance, you can inject some snippets in the conf/nginx.conf via configuring the xxx_snippet entries:

  1. ...
  2. # put this in config.yaml:
  3. nginx_config:
  4. main_configuration_snippet: |
  5. daemon on;
  6. http_configuration_snippet: |
  7. server
  8. {
  9. listen 45651;
  10. server_name _;
  11. access_log off;
  12. location /ysec_status {
  13. req_status_show;
  14. allow 127.0.0.1;
  15. deny all;
  16. }
  17. }
  18. chunked_transfer_encoding on;
  19. http_server_configuration_snippet: |
  20. set $my "var";
  21. http_admin_configuration_snippet: |
  22. log_format admin "$request_time $pipe";
  23. http_end_configuration_snippet: |
  24. server_names_hash_bucket_size 128;
  25. stream_configuration_snippet: |
  26. tcp_nodelay off;
  27. ...

Pay attention to the indent of nginx_config and sub indent of the sub entries, the incorrect indent may cause ./bin/apisix start to fail to generate Nginx configuration in conf/nginx.conf.