kong配置参考

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kong配置参考相关的知识,希望对你有一定的参考价值。

参考技术A 可以通过如下环境变量来覆盖上面配置文件中的配置项

比如添加如下配置到kong.conf

将添加如下配置到nginx配置的server 块

同样的,跟其他配置项一样也支持环境变量配置

将添加如下配置项到nginx配置的http块

可以通过kong.conf或者环境变量添加配置

这时可以访问2112端口了

绝大多数情况下你可以通过上续的方法定制kong的nginx实例的行为,通过单个kong.conf管理kong的配置和调优,而无需自定义nginx配置模板。但是有两种情况你可能需要用到nignx的配置模板:

kong可以使用--nginx-conf参数指定一个nginx配置模板来启动、重新加载或者重启,nginx模板使用Penlight模板引擎,该引擎使用给定的Kong配置进行编译,然后在启动Nginx之前将其转储到您的Kong前缀目录中。

默认的模板可以在 https://github.com/kong/kong/tree/master/kong/templates 找到,它分割为了个nginx配置文件:nginx.lua 和 nginx_kong.lua,前者是简约的,并且引入了后者,包含了运行kong需要的所有东西。当kong启动的时候,nginx会优先启动,并且复制这两个文件到prefix 目录(-p指定的目录),就像如下所示:

如果你必须调整由kong定义但又不能通过kong.conf文件配置的全局设置,可以将nginx_kong.lua的内容内联到一个自定义的模板文件(在这个例子中叫custom_nginx.template),如下所示:

然后使用如下命令启动kong

如果你已经运行了自己的openresty服务器,你也可以很容易的使用include指令引入kong nginx子配置来嵌入kong。如果你已经有了一个nginx配置文件,你可以简单的通过kong输出一些特定的配置到一个单独的配置文件nginx-kong.conf:

使用如下命令启动openresty

然后kong将运行在这个实例中。

一个常见的api服务场景是通过80或者443端口同时提供网站和api服务,比如 https://example.net (网站)以及 https://example.net/api/v1 (api)
为了实现这个目的,我们不能像前面已经简单的定义两个新的虚拟server块,一个更好的解决方案是使用自定义nginx配置模板内联nginx_kong.lua,并添加一个新的location块为kong proxy location块提供服务。

微服务Kong——CLI参考

KONG提供了一套CLI(命令行界面)命令,您可以通过它来启动、停止和管理您的Kong实例。CLI管理您的本地节点(如在当前机器上)。

  全局配置

    所有命令都采用一组指定的可选标志作为参数:

      --help:显示命令行帮助信息

      --v:启动详情模式

      --vv:启动debug模式(noisy)

  可用的命令符

    kong check:

Usage: kong check <conf>

Check the validity of a given Kong configuration file.

<conf> (default /etc/kong.conf) configuration file

    kong cluster:

Usage: kong cluster COMMAND [OPTIONS]

Manage Kongs clustering capabilities.

The available commands are:
  keygen -c                   Generate an encryption key for intracluster traffic.
                              See cluster_encrypt_key setting
  members -p                  Show members of this cluster and their state.
  reachability -p             Check if the cluster is reachable.
  force-leave -p <node_name>  Forcefully remove a node from the cluster (useful
                              if the node is in a failed state).
  keys install <key>          Install a new key onto Kongs internal keyring. This
                              will enable the key for decryption. The key will not
                              be used to encrypt messages until the primary key is
                              changed.
  keys use <key>              Change the primary key used for encrypting messages.
                              All nodes in the cluster must already have this key
                              installed if they are to continue communicating with
                              eachother.
  keys remove <key>           Remove a key from Kongs internal keyring. The key
                              being removed may not be the current primary key.
  keys list                   List all currently known keys in the cluster. This
                              will ask all nodes in the cluster for a list of keys
                              and dump a summary containing each key and the
                              number of members it is installed on to the console.

Options:
  -c,--conf   (optional string) configuration file
  -p,--prefix (optional string) prefix Kong is running at

    kong compile:

Usage: kong compile [OPTIONS]

Compile the Nginx configuration file containing Kongs servers
contexts from a given Kong configuration file.

Example usage:
  kong compile -c kong.conf > /usr/local/openresty/nginx-kong.conf

  This file can then be included in an OpenResty configuration:

  http {
      # ...
      include nginx-kong.conf;
  }

Note:
  Third-party services such as Serf need to be properly configured
  and started for Kong to be fully compatible while embedded.

Options:
  -c,--conf (optional string) configuration file

    kong health:

Usage: kong health [OPTIONS]

Check if the necessary services are running for this node.

Options:
  -p,--prefix (optional string) prefix at which Kong should be running

    kong migrations:

Usage: kong migrations COMMAND [OPTIONS]

Manage Kongs database migrations.

The available commands are:
  list   List migrations currently executed.
  up     Execute all missing migrations up to the latest available.
  reset  Reset the configured database (irreversible).

Options:
  -c,--conf (optional string) configuration file

    kong quit:

Usage: kong quit [OPTIONS]

Gracefully quit a running Kong node (Nginx and other
configured services) in given prefix directory.

This command sends a SIGQUIT signal to Nginx, meaning all
requests will finish processing before shutting down.
If the timeout delay is reached, the node will be forcefully
stopped (SIGTERM).

Options:
  -p,--prefix  (optional string) prefix Kong is running at
  -t,--timeout (default 10) timeout before forced shutdown

    kong reload:

Usage: kong reload [OPTIONS]

Reload a Kong node (and start other configured services
if necessary) in given prefix directory.

This command sends a HUP signal to Nginx, which will spawn
new workers (taking configuration changes into account),
and stop the old ones when they have finished processing
current requests.

Options:
  -c,--conf    (optional string) configuration file
  -p,--prefix  (optional string) prefix Kong is running at
  --nginx-conf (optional string) custom Nginx configuration template

    kong restart:

Usage: kong restart [OPTIONS]

Restart a Kong node (and other configured services like Serf)
in the given prefix directory.

This command is equivalent to doing both kong stop and
kong start.

Options:
  -c,--conf    (optional string) configuration file
  -p,--prefix  (optional string) prefix at which Kong should be running
  --nginx-conf (optional string) custom Nginx configuration template

    kong start:

Usage: kong start [OPTIONS]

Start Kong (Nginx and other configured services) in the configured
prefix directory.

Options:
  -c,--conf    (optional string) configuration file
  -p,--prefix  (optional string) override prefix directory
  --nginx-conf (optional string) custom Nginx configuration template

    kong stop:

Usage: kong stop [OPTIONS]

Stop a running Kong node (Nginx and other configured services) in given
prefix directory.

This command sends a SIGTERM signal to Nginx.

Options:
  -p,--prefix (optional string) prefix Kong is running at

    kong version:

Usage: kong version [OPTIONS]

Print Kongs version. With the -a option, will print
the version of all underlying dependencies.

Options:
  -a,--all    get version of all dependencies

 

  • --help: print the command‘s help message

以上是关于kong配置参考的主要内容,如果未能解决你的问题,请参考以下文章

微服务Kong——CLI参考

微服务Kong——认证参考

Kong 网关配置开源WAF组件

Kong网关之负载均衡、动态路由配置

KONG API配置UPSTREAM

API网关Kong使用指南(四)—— hmac-auth插件配置