Skip to content

Commit de2bcae

Browse files
lovasoacursoragent
andcommitted
Document nginx streaming and compression for sqlpage (#1080)
* Docs: Add Nginx streaming and compression configuration Co-authored-by: contact <[email protected]> * Add NGINX streaming and compression configuration Co-authored-by: contact <[email protected]> * Refactor NGINX proxy settings documentation for clarity Co-authored-by: contact <[email protected]> * Refine NGINX proxy buffering recommendations for streaming Co-authored-by: contact <[email protected]> * Update NGINX proxy buffering settings for improved streaming performance Revised the documentation to clarify the impact of enabling and disabling proxy buffering in NGINX for SQLPage. Added concise recommendations for handling slow SQL queries and emphasized the importance of adjusting `compress_responses` in `sqlpage.json` when using a reverse proxy. Co-authored-by: contact <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent 70a2612 commit de2bcae

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

examples/nginx/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ This service sets up a MySQL database with predefined credentials and a persiste
4343

4444
The `nginx.conf` file contains the NGINX configuration:
4545

46+
### Streaming and compression
47+
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:
49+
50+
```
51+
proxy_buffering on;
52+
proxy_buffer_size 16k;
53+
proxy_buffers 4 16k;
54+
55+
gzip on;
56+
gzip_buffers 2 4k;
57+
gzip_types text/html text/plain text/css application/javascript application/json;
58+
59+
chunked_transfer_encoding on;
60+
```
61+
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.
63+
64+
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.
65+
4666
### Rate Limiting
4767

4868

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ sudo systemctl reload nginx
6565

6666
Your SQLPage instance is now hosted behind a reverse proxy using NGINX. You can access it by visiting `http://example.com`.
6767

68+
69+
### Streaming-friendly proxy settings
70+
71+
SQLPage streams HTML by default so the browser can render results while the database is still sending rows.
72+
If you have slow SQL queries (you shouldn't), you can add the following directive to your location block:
73+
74+
```nginx
75+
proxy_buffering off;
76+
```
77+
78+
That will allow users to start seeing the top of your pages faster,
79+
but will increase the load on your SQLPage server, and reduce the amount of users you can serve concurrently.
80+
81+
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.
82+
83+
When SQLPage sits behind a reverse proxy, set `compress_responses` to `false` [in `sqlpage.json`](https://github.com/sqlpage/SQLPage/blob/main/configuration.md) so that NGINX compresses once at the edge.
84+
6885
### URL Rewriting
6986

7087
URL rewriting is a powerful feature that allows you to manipulate URLs to make them more readable, search-engine-friendly, and easy to maintain.

0 commit comments

Comments
 (0)