Skip to content

pitfall: proxy_pass with var requires proxy_redirect #2

Closed
@lcarva

Description

@lcarva

When a variable is used in proxy_pass directive, the location header is not longer adjusted. This causes the value coming from backend to make its way back to client. To get around this, simply set proxy_redirect.

This will not fix up location redirect:

location = /proxy/ {
    set $endpoint proxy.com;
    resolver 8.8.8.8 valid=10s;
    proxy_pass https://$endpoint/;
}

This will:

location = /proxy/ {
    set $endpoint proxy.com;
    resolver 8.8.8.8 valid=10s;
    proxy_pass https://$endpoint/;
    proxy_redirect https://$endpoint/ /;
}

You can define proxy_redirect on server context if used in multiple locations.
This a single line in docs that mention it:

The default parameter is not permitted if proxy_pass is specified using variables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions