Skip to content

Commit 1403b2c

Browse files
authored
Add request header tutorial to how-to guides (#2715)
Add request header tutorial to how-to guides Problem: Users need a consolidated document for both request and response header modifiers Solution: Updated existing response header modifier guide with request header modifier docs.
1 parent 71a6c5c commit 1403b2c

File tree

5 files changed

+357
-303
lines changed

5 files changed

+357
-303
lines changed
Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,3 @@
1-
# Example
1+
# HTTP request headers example
22

3-
In this example we will deploy NGINX Gateway Fabric and configure traffic routing for a simple echo server.
4-
We will use HTTPRoute resources to route traffic to the echo server, using the `RequestHeaderModifier` filter to modify
5-
headers to the request.
6-
7-
## Running the Example
8-
9-
## 1. Deploy NGINX Gateway Fabric
10-
11-
1. Follow the [installation instructions](https://docs.nginx.com/nginx-gateway-fabric/installation/) to deploy NGINX Gateway Fabric.
12-
13-
1. Save the public IP address of NGINX Gateway Fabric into a shell variable:
14-
15-
```text
16-
GW_IP=XXX.YYY.ZZZ.III
17-
```
18-
19-
1. Save the port of NGINX Gateway Fabric:
20-
21-
```text
22-
GW_PORT=<port number>
23-
```
24-
25-
## 2. Deploy the Headers Application
26-
27-
1. Create the headers Deployment and Service:
28-
29-
```shell
30-
kubectl apply -f headers.yaml
31-
```
32-
33-
1. Check that the Pod is running in the `default` Namespace:
34-
35-
```shell
36-
kubectl -n default get pods
37-
```
38-
39-
```text
40-
NAME READY STATUS RESTARTS AGE
41-
headers-6f4b79b975-2sb28 1/1 Running 0 12s
42-
```
43-
44-
## 3. Configure Routing
45-
46-
1. Create the Gateway:
47-
48-
```shell
49-
kubectl apply -f gateway.yaml
50-
```
51-
52-
1. Create the HTTPRoute resources:
53-
54-
```shell
55-
kubectl apply -f echo-route.yaml
56-
```
57-
58-
## 4. Test the Application
59-
60-
To access the application, we will use `curl` to send requests to the `headers` Service, including sending headers with
61-
our request.
62-
Notice our configured header values can be seen in the `requestHeaders` section below, and that the `User-Agent` header
63-
is absent.
64-
65-
```shell
66-
curl -s --resolve echo.example.com:$GW_PORT:$GW_IP http://echo.example.com:$GW_PORT/headers -H "My-Cool-Header:my-client-value" -H "My-Overwrite-Header:dont-see-this"
67-
```
68-
69-
```text
70-
Headers:
71-
header 'Accept-Encoding' is 'compress'
72-
header 'My-cool-header' is 'my-client-value, this-is-an-appended-value'
73-
header 'My-Overwrite-Header' is 'this-is-the-only-value'
74-
header 'Host' is 'echo.example.com:$GW_PORT'
75-
header 'X-Forwarded-For' is '$GW_IP'
76-
header 'Connection' is 'close'
77-
header 'Accept' is '*/*'
78-
```
3+
This directory contains the YAML files used in the [Modify HTTP request and response headers](https://docs.nginx.com/nginx-gateway-fabric/how-to/traffic-management/request-response-headers/) guide.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# HTTP Response Headers
1+
# HTTP response headers example
22

3-
This directory contains the YAML files used in the [HTTP Response Headers](https://docs.nginx.com/nginx-gateway-fabric/how-to/traffic-management/response-headers/) guide.
3+
This directory contains the YAML files used in the [Modify HTTP request and response headers](https://docs.nginx.com/nginx-gateway-fabric/how-to/traffic-management/request-response-headers/) guide.

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ as arguments and add `/bin/sh` as the command. The deployment manifest should lo
160160

161161
## Configure PROXY protocol and RewriteClientIP settings
162162

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 the `NginxProxy` resource. `RewriteClientIP` has the fields: _mode_, _trustedAddresses_ and _setIPRecursively_.
163+
When a 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 the `NginxProxy` resource. `RewriteClientIP` has the fields: _mode_, _trustedAddresses_ and _setIPRecursively_.
164164

165165
**Mode** determines how the original client IP is passed through multiple proxies and the way the load balancer is set to receive it. It can have two values:
166166

@@ -173,7 +173,7 @@ The choice of mode depends on how the load balancer fronting NGINX Gateway Fabri
173173

174174
**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.
175175

176-
The following command creates an `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.
176+
The following command creates an `NginxProxy` resource with `RewriteClientIP` settings that set the mode to ProxyProtocol and sets a CIDR in the list of trusted addresses to find the original client IP address.
177177

178178
```yaml
179179
kubectl apply -f - <<EOF
@@ -184,18 +184,13 @@ metadata:
184184
spec:
185185
config:
186186
rewriteClientIP:
187-
mode: XForwardedFor
188-
setIPRecursively: true
187+
mode: ProxyProtocol
189188
trustedAddresses:
190189
- type: CIDR
191-
value: ":1/28"
192-
- type: IPAddress
193-
value: "192.68.74.28"
194-
- type: Hostname
195-
value: "cafe.com"
190+
value "76.89.90.11/24"
196191
EOF
197192
```
198193

199-
For more information, see the `NginxProxy spec` in the [API reference]({{< relref "reference/api.md" >}}).
194+
For the full configuration API, see the `NginxProxy spec` in the [API reference]({{< relref "reference/api.md" >}}).
200195

201-
{{< note >}} When sending curl requests to a server expecting proxy information, use the flag `--harproxy-protocol` to avoid broken header errors. {{< /note >}}
196+
{{< note >}} When sending curl requests to a server expecting proxy information, use the flag `--haproxy-protocol` to avoid broken header errors. {{< /note >}}

0 commit comments

Comments
 (0)