header_upstream name value
header_downstream name value
header_upstream name regex replacement
header_downstream name regex replacement
- (existing header_upstream doc)
- header_upstream can also be used with an extra argument, where the field name is name, the regular expression to match in it is regex, and the value to replace the match with is value. This option allows values within headers to be modified based on those values, can be specified multiple times for multiple headers and for multiple modifications of the same header. Capture groups are supported and substituted into the replacement (as $1, $2, etc.) and request placeholders can be used in the replacement. The regular expressions use Go's syntax described here.
- (existing header_downstream doc)
- header_downstream can also be used with an extra argument, in the same way header_upstream can.
Rewrite redirects (301, 302, 307 etc) going to localhost so that they go to example.com instead:
proxy / localhost:8080 {
header_downstream Location localhost example.com
}
Remove a cookie being sent from the backend server to the client, and a cookie being sent from the client to the backend server:
proxy / localhost:8080 {
header_downstream Set-Cookie "^Tracking=.*" ""
header_upstream Cookie "(.*)(^Tracking=[^;]*; |; Tracking=[^;]*|^Tracking=[^;]*$)(.*)" "$1 $3"
}