Skip to content

Commit f0c8344

Browse files
se2342wandenberg
authored andcommitted
improve README
1 parent e5bbded commit f0c8344

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

README.md

+51-48
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
Nginx Sorted Querystring Module
22
===============================
33

4-
A module to order the querystring parameters in a variable to be used as cache key.
4+
This Nginx module orders the querystring parameters of an HTTP request alphanumerically and makes the sorted key-value pairs accessible using an Nginx variable.
55

6-
Requests like /index.html?b=2&a=1&c=3, /index.html?b=2&c=3&a=1, /index.html?c=3&a=1&b=2, /index.html?c=3&b=2&a=1 will produce the same value for `$sorted_querystring_args` _'a=1&b=2&c=3'_.
6+
Requests like `/index.html?b=2&a=1&c=3`, `/index.html?b=2&c=3&a=1`, `/index.html?c=3&a=1&b=2`, `/index.html?c=3&b=2&a=1` will produce the same normalized querystring `a=1&b=2&c=3` which can be accessed within Nginx using the `$sorted_querystring_args` variable.
77

8-
It is also possible remove some undesired parameter defining its name with `sorted_querysting_filter_parameter`, like `sorted_querysting_filter_parameter b _ foo;` resulting in a `$sorted_querystring_args` as _'a=1&c=3'_
8+
This is especially useful if you want to normalize the querystring to be used in a cache key, for example when used with the `proxy_cache_key` directive.
9+
10+
It is also possible to remove one or more undesired query parameters by defining their name with the `sorted_querysting_filter_parameter` directive, like `sorted_querystring_filter_parameter <parameter_name> [<parameter_name> <parameter_name> ...];`.
911

1012
_This module is not distributed with the Nginx source. See [the installation instructions](#installation)._
1113

@@ -15,68 +17,69 @@ Configuration
1517

1618
An example:
1719

18-
pid logs/nginx.pid;
19-
error_log logs/nginx-main_error.log debug;
20+
```
21+
pid logs/nginx.pid;
22+
error_log logs/nginx-main_error.log debug;
2023
21-
worker_processes 2;
24+
worker_processes 2;
2225
23-
events {
24-
worker_connections 1024;
25-
#use kqueue; # MacOS
26-
use epoll; # Linux
27-
}
26+
events {
27+
worker_connections 1024;
28+
#use kqueue; # MacOS
29+
use epoll; # Linux
30+
}
2831
29-
http {
30-
default_type text/plain;
32+
http {
33+
default_type text/plain;
3134
32-
types {
33-
text/html html;
34-
}
35+
types {
36+
text/html html;
37+
}
3538
36-
log_format main '[$time_local] $host "$request" $request_time s '
37-
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
38-
'cache_status: "$upstream_cache_status" args: "$args '
39-
'sorted_args: "$sorted_querystring_args" ';
39+
log_format main '[$time_local] $host "$request" $request_time s '
40+
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
41+
'cache_status: "$upstream_cache_status" args: "$args '
42+
'sorted_args: "$sorted_querystring_args" ';
4043
41-
access_log logs/nginx-http_access.log;
44+
access_log logs/nginx-http_access.log;
4245
43-
proxy_cache_path /tmp/cache levels=1:2 keys_zone=zone:10m inactive=10d max_size=100m;
46+
proxy_cache_path /tmp/cache levels=1:2 keys_zone=zone:10m inactive=10d max_size=100m;
4447
45-
server {
46-
listen 8080;
47-
server_name localhost;
48+
server {
49+
listen 8080;
50+
server_name localhost;
4851
49-
access_log logs/nginx-http_access.log main;
52+
access_log logs/nginx-http_access.log main;
5053
51-
location /filtered {
52-
sorted_querysting_filter_parameter v _ time b;
54+
location /filtered {
55+
sorted_querysting_filter_parameter v _ time b;
5356
54-
proxy_set_header Host "static_files_server";
55-
proxy_pass http://localhost:8081;
57+
proxy_set_header Host "static_files_server";
58+
proxy_pass http://localhost:8081;
5659
57-
proxy_cache zone;
58-
proxy_cache_key "$sorted_querystring_args";
59-
proxy_cache_valid 200 1m;
60-
}
60+
proxy_cache zone;
61+
proxy_cache_key "$sorted_querystring_args";
62+
proxy_cache_valid 200 1m;
63+
}
6164
62-
location / {
63-
proxy_pass http://localhost:8081;
65+
location / {
66+
proxy_pass http://localhost:8081;
6467
65-
proxy_cache zone;
66-
proxy_cache_key "$sorted_querystring_args";
67-
proxy_cache_valid 200 10m;
68-
}
68+
proxy_cache zone;
69+
proxy_cache_key "$sorted_querystring_args";
70+
proxy_cache_valid 200 10m;
6971
}
72+
}
7073
71-
server {
72-
listen 8081;
74+
server {
75+
listen 8081;
7376
74-
location / {
75-
return 200 "$args\n";
76-
}
77+
location / {
78+
return 200 "$args\n";
7779
}
7880
}
79-
81+
}
82+
```
8083

8184
Variables
8285
---------
@@ -90,7 +93,7 @@ Directives
9093
* **sorted_querystring_filter_parameter** - list parameters to be filtered while using the `$sorted_querystring_args` variable.
9194

9295

93-
<a id="installation"></a>Installation instructions
96+
<a id="installation"></a>Installation Instructions
9497
--------------------------------------------------
9598

9699
[Download Nginx Stable](http://nginx.org/en/download.html) source and uncompress it (ex.: to ../nginx). You must then run ./configure with --add-module pointing to this project as usual. Something in the lines of:
@@ -102,7 +105,7 @@ Directives
102105
$ make install
103106

104107

105-
Running tests
108+
Running Tests
106109
-------------
107110

108111
This project uses [nginx_test_helper](https://github.com/wandenberg/nginx_test_helper) on the test suite. So, after you've installed the module, you can just download the necessary gems:

0 commit comments

Comments
 (0)