Skip to content

Commit 6ca6d50

Browse files
authored
Merge pull request #92 from dvershinin/pr-37-fixed
plugin: detect low keepalive_requests (fixed for crossplane)
2 parents 99aa9fc + 4865ea9 commit 6ca6d50

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Low `keepalive_requests` value
2+
3+
The `keepalive_requests` directive sets the maximum number of requests that can be served through one keep-alive connection. After the maximum number of requests are made, the connection is closed.
4+
5+
## Why this matters
6+
7+
Prior to nginx 1.19.10, the default value was 100. This was raised to 1000 because low values can cause problems:
8+
9+
- **HTTP/2 multiplexing**: Modern browsers open fewer connections but send many requests over each one. A low `keepalive_requests` value forces frequent connection resets.
10+
- **Client disconnections**: Some clients (especially when using HTTP/2 with proxies like Burp or mitmproxy) may experience failed requests when connections are closed prematurely.
11+
- **Performance overhead**: Establishing new connections has overhead (TCP handshake, TLS negotiation). Keeping connections alive longer improves performance.
12+
13+
## Bad example
14+
15+
```nginx
16+
keepalive_requests 100;
17+
```
18+
19+
This forces connection closure after only 100 requests, which can cause issues with HTTP/2 clients.
20+
21+
## Good example
22+
23+
```nginx
24+
keepalive_requests 1000;
25+
```
26+
27+
Or simply omit the directive to use nginx's default (1000 since nginx 1.19.10).
28+
29+
## References
30+
31+
- [nginx documentation: keepalive_requests](https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_requests)
32+
- [nginx ticket #2155: Increase default keepalive_requests](https://trac.nginx.org/nginx/ticket/2155)
33+
34+
--8<-- "en/snippets/nginx-extras-cta.md"
35+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Module for low_keepalive_requests plugin."""
2+
3+
import gixy
4+
from gixy.plugins.plugin import Plugin
5+
6+
7+
class low_keepalive_requests(Plugin):
8+
"""
9+
Insecure example:
10+
keepalive_requests 100;
11+
"""
12+
13+
summary = "The keepalive_requests directive should be at least 1000."
14+
severity = gixy.severity.LOW
15+
description = "The keepalive_requests directive should be at least 1000. Any value lower than this may result in client disconnections."
16+
help_url = "https://gixy.getpagespeed.com/en/plugins/low_keepalive_requests/"
17+
directives = ["keepalive_requests"]
18+
19+
def audit(self, directive):
20+
if not directive.args:
21+
return
22+
try:
23+
value = int(directive.args[0])
24+
except (ValueError, TypeError, IndexError):
25+
return
26+
if value < 1000:
27+
self.add_issue(
28+
severity=self.severity,
29+
directive=[directive],
30+
reason="The keepalive_requests directive should be at least 1000.",
31+
)
32+

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ nav:
5151
- plugins/unanchored_regex.md
5252
- plugins/regex_redos.md
5353
- plugins/worker_rlimit_nofile_vs_connections.md
54+
- plugins/low_keepalive_requests.md
5455
- 'NGINX Extras RPMs': 'https://nginx-extras.getpagespeed.com/'
5556
- 'Blog': 'https://www.getpagespeed.com/posts'
5657
markdown_extensions:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
keepalive_requests 100;
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
keepalive_requests 1000;
2+

0 commit comments

Comments
 (0)