Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add request header tutorial to how-to guides #2715

Merged
merged 33 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
59e8565
update doc to add request header to how to guides
salonichf5 Oct 22, 2024
9035521
update rewrite client IP doc
salonichf5 Oct 22, 2024
341637d
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
1b9f8e0
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
3f6e706
update based on reviews
salonichf5 Oct 23, 2024
5e0036d
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
2ecaf0b
Update examples/http-request-header-filter/README.md
salonichf5 Oct 23, 2024
ce05242
Update examples/http-request-header-filter/README.md
salonichf5 Oct 23, 2024
0992e1a
Update examples/http-response-header-filter/README.md
salonichf5 Oct 23, 2024
b2d37bd
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
3f8e1c1
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
17ee2a1
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
4ef4bc1
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
1639496
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
0f18d58
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
37f6a73
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
6d37b0d
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
eb21ba2
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
8f1c3ea
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
44a8496
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
202416e
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
364137f
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
261ce53
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
3388802
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
50f8aa7
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
0ae238c
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
9781ed0
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
4894da9
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 23, 2024
efc4d64
updates for consistency
salonichf5 Oct 23, 2024
0f98c61
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 24, 2024
664a9eb
Update site/content/how-to/traffic-management/request-response-header…
salonichf5 Oct 24, 2024
ed2f050
Apply suggestions from code review
salonichf5 Oct 24, 2024
05ed810
update guide name
salonichf5 Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 2 additions & 77 deletions examples/http-request-header-filter/README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
# Example
# HTTP request headers example

In this example we will deploy NGINX Gateway Fabric and configure traffic routing for a simple echo server.
We will use HTTPRoute resources to route traffic to the echo server, using the `RequestHeaderModifier` filter to modify
headers to the request.

## Running the Example

## 1. Deploy NGINX Gateway Fabric

1. Follow the [installation instructions](https://docs.nginx.com/nginx-gateway-fabric/installation/) to deploy NGINX Gateway Fabric.

1. Save the public IP address of NGINX Gateway Fabric into a shell variable:

```text
GW_IP=XXX.YYY.ZZZ.III
```

1. Save the port of NGINX Gateway Fabric:

```text
GW_PORT=<port number>
```

## 2. Deploy the Headers Application

1. Create the headers Deployment and Service:

```shell
kubectl apply -f headers.yaml
```

1. Check that the Pod is running in the `default` Namespace:

```shell
kubectl -n default get pods
```

```text
NAME READY STATUS RESTARTS AGE
headers-6f4b79b975-2sb28 1/1 Running 0 12s
```

## 3. Configure Routing

1. Create the Gateway:

```shell
kubectl apply -f gateway.yaml
```

1. Create the HTTPRoute resources:

```shell
kubectl apply -f echo-route.yaml
```

## 4. Test the Application

To access the application, we will use `curl` to send requests to the `headers` Service, including sending headers with
our request.
Notice our configured header values can be seen in the `requestHeaders` section below, and that the `User-Agent` header
is absent.

```shell
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"
```

```text
Headers:
header 'Accept-Encoding' is 'compress'
header 'My-cool-header' is 'my-client-value, this-is-an-appended-value'
header 'My-Overwrite-Header' is 'this-is-the-only-value'
header 'Host' is 'echo.example.com:$GW_PORT'
header 'X-Forwarded-For' is '$GW_IP'
header 'Connection' is 'close'
header 'Accept' is '*/*'
```
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.
salonichf5 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions examples/http-response-header-filter/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# HTTP Response Headers
# HTTP response headers example

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.
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.
salonichf5 marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 6 additions & 11 deletions site/content/how-to/data-plane-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ as arguments and add `/bin/sh` as the command. The deployment manifest should lo

## Configure PROXY protocol and RewriteClientIP settings

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_.
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_.

**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:

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

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

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.
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.

```yaml
kubectl apply -f - <<EOF
Expand All @@ -184,18 +184,13 @@ metadata:
spec:
config:
rewriteClientIP:
mode: XForwardedFor
setIPRecursively: true
mode: ProxyProtocol
trustedAddresses:
- type: CIDR
value: ":1/28"
- type: IPAddress
value: "192.68.74.28"
- type: Hostname
value: "cafe.com"
value "76.89.90.11/24"
EOF
```

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

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