You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+1-2
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,7 @@ In short, this SDK allows writing NGINX modules using the Rust language.
12
12
13
13
## Build
14
14
15
-
NGINX modules can be build against a particular version of NGINX. The following environment variables can be used to
16
-
specify particular version of NGINX or an NGINX dependency:
15
+
NGINX modules can be built against a particular version of NGINX. The following environment variables can be used to specify a particular version of NGINX or an NGINX dependency:
Copy file name to clipboardexpand all lines: examples/README.md
+55-4
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,65 @@
1
+
-[Examples](#examples)
2
+
-[CURL](#curl)
3
+
-[AWSSIG](#awssig)
4
+
-[HTTPORIGDST - NGINX Destination IP recovery module for HTTP](#httporigdst----nginx-destination-ip-recovery-module-for-http)
5
+
-[Dependencies](#dependencies)
6
+
-[Example Configuration](#example-configuration)
7
+
-[HTTP](#http)
8
+
-[Embedded Variables](#embedded-variables)
9
+
-[Usage](#usage)
10
+
-[Caveats](#caveats)
11
+
12
+
1
13
# Examples
14
+
This crate provides a couple of example using [ngx](https://crates.io/crates/ngx) crate:
15
+
16
+
-[awssig.rs](./awssig.rs) - An example of NGINX dynamic module that can sign GET request using AWS Signature v4.
17
+
-[curl](./curl.rs) - An example of the Access Phase NGINX dynamic module that blocks HTTP requests if `user-agent` header starts with `curl`.
18
+
-[httporigdst](./httporigdst.rs) - A dynamic module recovers the original IP address and port number of the destination packet.
19
+
20
+
To build all these examples simply run:
21
+
22
+
```
23
+
cargo build --package=examples --examples
24
+
```
25
+
26
+
27
+
## CURL
28
+
29
+
This module demonstrates how to create a minimal dynamic module with `http_request_handler`, that checks for User-Agent headers and returns status code 403 if UA starts with `curl`, if a module is disabled then uses `core::Status::NGX_DECLINED` to indicate the operation is rejected, for example, because it is disabled in the configuration (`curl off`). Additionally, it demonstrates how to write a defective parser.
30
+
31
+
An example of nginx configuration file that uses that module can be found at [curl.conf](./curl.conf).
2
32
3
-
## NGINX Destination IP recovery module for HTTP
33
+
How to build and run in a [Docker](../Dockerfile) container curl example:
34
+
```
35
+
# build all dynamic modules examples and specify NGINX version to use
This dynamic module recovers original IP address and port number of the destination packet. It is useful, for example, with container sidecars where all outgoing traffic is redirected to a separate container with iptables before reaching the target.
49
+
## AWSSIG
50
+
51
+
This module uses [NGX_HTTP_PRECONTENT_PHASE](https://nginx.org/en/docs/dev/development_guide.html#http_phases) and provides examples, of how to use external dependency and manipulate HTTP headers before sending client requests upstream.
52
+
53
+
An example of nginx configuration file that uses that module can be found at [awssig.conf](./awssig.conf).
54
+
55
+
## HTTPORIGDST - NGINX Destination IP recovery module for HTTP
56
+
57
+
This dynamic module recovers the original IP address and port number of the destination packet. It is useful, for example, with container sidecars where all outgoing traffic is redirected to a separate container with iptables before reaching the target.
6
58
7
59
This module can only be built with the "linux" feature enabled, and will only successfully build on a Linux OS.
8
60
9
61
### Dependencies
10
-
11
-
This modules uses the Rust crate libc and Linux **getsockopt** socket API.
62
+
This module uses the Rust crate libc and Linux **getsockopt** socket API.
0 commit comments