Skip to content

Commit 69e0fb3

Browse files
cursoragentlovasoa
andcommitted
Refine NGINX proxy buffering recommendations for streaming
Co-authored-by: contact <[email protected]>
1 parent d562c59 commit 69e0fb3

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

examples/nginx/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ The `nginx.conf` file contains the NGINX configuration:
4545

4646
### Streaming and compression
4747

48-
SQLPage streams HTML as it is generated, so browsers can start rendering before the database finishes returning rows. To keep that behaviour through NGINX, prefer minimal buffering and let the proxy handle compression:
48+
SQLPage streams HTML as it is generated, so browsers can start rendering before the database finishes returning rows. NGINX enables `proxy_buffering` by default, which can delay those first bytes but stores responses for slow clients. Start with a modest buffer configuration and let the proxy handle compression:
4949

5050
```
51-
proxy_buffering off;
51+
proxy_buffering on;
52+
proxy_buffer_size 16k;
53+
proxy_buffers 4 16k;
5254
5355
gzip on;
5456
gzip_buffers 2 4k;
@@ -57,7 +59,7 @@ SQLPage streams HTML as it is generated, so browsers can start rendering before
5759
chunked_transfer_encoding on;
5860
```
5961

60-
Disabling buffering lowers latency but increases the number of active connections; tune the gzip settings to balance CPU cost versus bandwidth, and re-enable buffering only if you need request coalescing or traffic smoothing. See the [proxy buffering](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering), [gzip](https://nginx.org/en/docs/http/ngx_http_gzip_module.html), and [chunked transfer](https://nginx.org/en/docs/http/ngx_http_core_module.html#chunked_transfer_encoding) directives for more guidance.
62+
Keep buffering when you expect slow clients or longer SQLPage queries, increasing the buffer sizes only if responses overflow. When most users are on fast connections reading lightweight pages, consider reducing the buffer counts or flipping to `proxy_buffering off;` to minimise latency, accepting the extra load on SQLPage. See the [proxy buffering](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering), [gzip](https://nginx.org/en/docs/http/ngx_http_gzip_module.html), and [chunked transfer](https://nginx.org/en/docs/http/ngx_http_core_module.html#chunked_transfer_encoding) directives for more guidance.
6163

6264
When SQLPage runs behind a reverse proxy, set `compress_responses` to `false` in its configuration (documented [here](https://github.com/sqlpage/SQLPage/blob/main/configuration.md)) so that NGINX can perform compression once at the edge.
6365

examples/official-site/your-first-sql-website/nginx.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ server {
5454

5555
### Streaming-friendly proxy settings
5656

57-
SQLPage streams HTML by default so the browser can render results while the database is still sending rows. To preserve this low-latency behaviour through NGINX, add the following directives inside the same `location` block as `proxy_pass`:
57+
SQLPage streams HTML by default so the browser can render results while the database is still sending rows. NGINX keeps `proxy_buffering` enabled by default, which smooths bursts and protects upstreams from slow clients at the cost of delaying the first bytes. Start with these directives inside the same `location` block as `proxy_pass`:
5858

5959
```nginx
60-
proxy_buffering off;
60+
proxy_buffering on;
61+
proxy_buffer_size 16k;
62+
proxy_buffers 4 16k;
6163
6264
gzip on;
6365
gzip_buffers 2 4k;
@@ -66,7 +68,7 @@ SQLPage streams HTML by default so the browser can render results while the data
6668
chunked_transfer_encoding on;
6769
```
6870

69-
Disabling buffering lets responses reach clients immediately but increases how many simultaneous connections SQLPage must serve; raise the buffers only if you prefer smoothing bursts over fastest-first rendering. Tune the gzip buffer count and size to balance CPU cost and bandwidth, and keep chunked transfer enabled so streaming works with HTTP/1.1 clients. Consult the official NGINX documentation for [proxy buffering](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering), [gzip](https://nginx.org/en/docs/http/ngx_http_gzip_module.html), and [chunked transfer](https://nginx.org/en/docs/http/ngx_http_core_module.html#chunked_transfer_encoding) when adjusting these values. If you later implement heavy caching (see the section below), you may choose to reintroduce buffering for specific locations.
71+
Keep the default buffering behaviour when most visitors are on slow links (mobile, high latency) or when SQLPage queries run long (large aggregations, reports). Increase the buffer count or size if responses exceed these limits frequently, or leave them to NGINX defaults when unsure. For primarily fast clients reading light pages, you can switch to `proxy_buffering off;` or reduce the number of buffers to let the streamed HTML reach the browser sooner, accepting higher upstream connection pressure. Refer to the official documentation for [proxy buffering](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering), [gzip](https://nginx.org/en/docs/http/ngx_http_gzip_module.html), and [chunked transfer](https://nginx.org/en/docs/http/ngx_http_core_module.html#chunked_transfer_encoding) when tuning these values.
7072

7173
When SQLPage sits behind a reverse proxy, set `compress_responses` to `false` in `sqlpage.json` so that NGINX compresses once at the edge (documented [here](https://github.com/sqlpage/SQLPage/blob/main/configuration.md)).
7274

0 commit comments

Comments
 (0)