APISIX 是一个云原生 API 网关,是 Apache 软件基金会的顶级项目。
APISIX 从 etcd 中订阅获取所需的配置并以热更新的方式来更改自身行为,更改 etcd 中的配置即可完成对 APISIX 网关节点的控制,比如:动态上游、请求限速等。
快速上手
- 启动 APISIX
sudo apisix start
- 测试限流插件
为了方便测试,下面的示例中设置的是 60 秒最多只能有 2 个请求,如果超过就返回 503:
curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
{
"methods": ["GET"],
"uri": "/index.html",
"id": 1,
"plugin_config": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"39.97.63.215:80": 1
}
}
}'
$ curl -i http://127.0.0.1:9080/index.html HTTP/1.1 200 OK Content-Type: text/html Content-Length: 13175 Connection: keep-alive X-RateLimit-Limit: 2 X-RateLimit-Remaining: 1 Server: APISIX web server Date: Mon, 03 Jun 2019 09:38:32 GMT Last-Modified: Wed, 24 Apr 2019 00:14:17 GMT ETag: "5cbfaa59-3377" Accept-Ranges: bytes ...