diff --git a/docs/en/latest/plugins/limit-conn.md b/docs/en/latest/plugins/limit-conn.md index 6d40221ca02e..bc000ad75204 100644 --- a/docs/en/latest/plugins/limit-conn.md +++ b/docs/en/latest/plugins/limit-conn.md @@ -2,10 +2,9 @@ title: limit-conn keywords: - APISIX - - Plugin + - API Gateway - Limit Connection - - limit-con -description: This document contains information about the Apache APISIX limit-con Plugin. +description: This document contains information about the Apache APISIX limit-con Plugin, you can use it to limits the number of concurrent requests to your services. --- - ## Example usage -The example above configures the Plugin to only allow one concurrent request. When more than one request is received, the Plugin will respond with a 503 status code: +The example above configures the Plugin to only allow one connection on this route. When more than one request is received, the Plugin will respond with a `503` HTTP status code and reject the connection: -```bash +```shell curl -i http://127.0.0.1:9080/index.html?sleep=20 & curl -i http://127.0.0.1:9080/index.html?sleep=20 ``` -```bash +```shell 503 Service Temporarily Unavailable @@ -121,35 +120,15 @@ curl -i http://127.0.0.1:9080/index.html?sleep=20 ``` -## Disable Plugin - -To disable the `limit-conn` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. - -```bash -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' -{ - "methods": ["GET"], - "uri": "/index.html", - "id": 1, - "plugins": { - }, - "upstream": { - "type": "roundrobin", - "nodes": { - "127.0.0.1:1980": 1 - } - } -}' -``` - ## Limit the number of concurrent WebSocket connections Apache APISIX supports WebSocket proxy, we can use `limit-conn` plugin to limit the number of concurrent WebSocket connections. 1. Create a Route, enable the WebSocket proxy and the `limit-conn` plugin. -````shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +```shell +curl http://127.0.0.1:9180/apisix/admin/routes/1 \ +-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "uri": "/ws", "enable_websocket": true, @@ -170,13 +149,13 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 } } }' -```` +``` The above route enables the WebSocket proxy on `/ws`, and limits the number of concurrent WebSocket connections to 1. More than 1 concurrent WebSocket connection will return `503` to reject the request. -2. Initiate a WebSocket request, and the connection is established successfully +2. Initiate a WebSocket request, and the connection is established successfully. -````shell +```shell curl --include \ --no-buffer \ --header "Connection: Upgrade" \ @@ -189,23 +168,13 @@ curl --include \ ```shell HTTP/1.1 101 Switching Protocols -Connection: upgrade -Upgrade: websocket -Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= -Server: APISIX/2.15.0 -... -```` +``` -3. Initiate the WebSocket request again in another terminal, the request will be rejected +3. Initiate the WebSocket request again in another terminal, the request will be rejected. -````shell +```shell HTTP/1.1 503 Service Temporarily Unavailable -Date: Mon, 01 Aug 2022 03:49:17 GMT -Content-Type: text/html; charset=utf-8 -Content-Length: 194 -Connection: keep-alive -Server: APISIX/2.15.0 - +··· 503 Service Temporarily Unavailable @@ -213,4 +182,26 @@ Server: APISIX/2.15.0
openresty
-```` +``` + +## Disable Plugin + +To disable the `limit-conn` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. + +```shell +curl http://127.0.0.1:9180/apisix/admin/routes/1 \ +-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +{ + "methods": ["GET"], + "uri": "/index.html", + "id": 1, + "plugins": { + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + } +}' +``` diff --git a/docs/zh/latest/plugins/limit-conn.md b/docs/zh/latest/plugins/limit-conn.md index e274a609ac85..8f5a74dfe496 100644 --- a/docs/zh/latest/plugins/limit-conn.md +++ b/docs/zh/latest/plugins/limit-conn.md @@ -1,5 +1,10 @@ --- title: limit-conn +keywords: + - APISIX + - API 网关 + - Limit Connection +description: 本文介绍了 Apache APISIX limit-conn 插件的相关操作,你可以使用此插件限制客户端对服务的并发请求数。 ---