Skip to content

Commit d119f84

Browse files
committed
update docs for rewrite client IP settings
1 parent 9fb1d37 commit d119f84

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

site/content/how-to/data-plane-configuration.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,43 @@ as arguments and add `/bin/sh` as the command. The deployment manifest should lo
157157
- /bin/sh
158158
...
159159
```
160+
161+
### Configure Rewrite Client IP Settings
162+
163+
When the request is passed through multiple proxies or load balancers, the client IP is set to the IP address of the server that last handled the request. To preserve the original client IP address, you can configure `RewriteClientIP` settings in `NginxProxy` resource. `RewriteClientIP` has three fields *mode*, *trustedAddresses* and *setIPRecursively*. It is important to understand these fields to configure them according to your requirements.
164+
165+
**Mode** determines how the original client IP is passed through multiple proxies and the way load balancer is set to receive it. It can have two values:
166+
167+
1. `ProxyProtocol` is a protocol that carries connection information from the source requesting the connection to the destination for which the connection was requested.
168+
2. `XForwardedFor` is a multi-value HTTP header that is used by proxies to append IP addresses of the hosts that passed the request.
169+
170+
The choice of mode depends on how the load balancer fronting NGINX Gateway Fabric receives information.
171+
172+
**TrustedAddresses** are used to specify the IP addresses of the trusted proxies that pass the request. These can be in the form of CIDRs, IPs, or hostnames. For example, if a load balancer is forwarding the request to NGINX Gateway Fabric, the IP address of the load balancer should be specified in the `trustedAddresses` list to inform NGINX that the forwarded request is from a known source.
173+
174+
**SetIPRecursively** is a boolean field used to enable recursive search when selecting the client's address from a multi-value header. It is applicable in cases where we have a multi-value header containing client IPs to select from, i.e., when using `XForwardedFor` mode.
175+
176+
The following command creates a `NginxProxy` resource with `RewriteClientIP` settings that set the mode to XForwardedFor, enables recursive search for finding the client IP and sets a CIDR, IPAddress and Hostname in the list of trusted addresses to find the original client IP address.
177+
178+
```yaml
179+
kubectl apply -f - <<EOF
180+
apiVersion: gateway.nginx.org/v1alpha1
181+
kind: NginxProxy
182+
metadata:
183+
name: ngf-proxy-config
184+
spec:
185+
config:
186+
rewriteClientIP:
187+
mode: XForwardedFor
188+
setIPRecursively: true
189+
trustedAddresses: [
190+
{ type: CIDR, value: ":1/128" },
191+
{ type: IPAddress, value: "192.68.74.32"},
192+
{ type: Hostname, value: "cafe.com"},
193+
]
194+
EOF
195+
```
196+
197+
For more information, see the `NginxProxy spec` in the [API reference]({{< relref "reference/api.md" >}}).
198+
199+
{{<note>}}When sending curl request to a server expecting proxy information, use the flag `--harproxy-protocol` to avoid broken header errors. {{</ note >}}

site/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/nginxinc/nginx-gateway-fabric/site
22

33
go 1.21
44

5-
require github.com/nginxinc/nginx-hugo-theme v0.41.20 // indirect
5+
require github.com/nginxinc/nginx-hugo-theme v0.41.22 // indirect

site/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/nginxinc/nginx-hugo-theme v0.41.20 h1:6BJGRGdHW17OpkC4qbcHARo9TRrJPFrALBjFltwedf8=
22
github.com/nginxinc/nginx-hugo-theme v0.41.20/go.mod h1:DPNgSS5QYxkjH/BfH4uPDiTfODqWJ50NKZdorguom8M=
3+
github.com/nginxinc/nginx-hugo-theme v0.41.22 h1:Gb/OLbpumNqp8vOPkZzO2GmgPDRd1yr2tWHWUBHg8BA=
4+
github.com/nginxinc/nginx-hugo-theme v0.41.22/go.mod h1:DPNgSS5QYxkjH/BfH4uPDiTfODqWJ50NKZdorguom8M=

0 commit comments

Comments
 (0)