自定义 Nginx 配置

APISIX 会通过 apisix/cli/ngx_tpl.lua 这个模板和 conf/config-default.yamlconf/config.yaml 的配置生成 Nginx 配置文件。

在执行完 ./bin/apisix start,你可以在 conf/nginx.conf 看到生成的 Nginx 配置文件。

在自定义 Nginx 配置文件之前,烦请仔细阅读 conf/config-default.yaml。你可以在 conf/config.yaml 里面覆盖掉默认值。举个例子,你可以通过 xxx_snippet 之类的配置,在 conf/nginx.conf 里面注入你的自定义配置:

  1. ...
  2. # 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. ...

注意nginx_config及其子项的格式缩进,在执行./bin/apisix start时,错误的缩进将导致更新conf/nginx.conf文件失败。