Answer the question
In order to leave comments, you need to log in
How to implement NGINX proxy with adding header when URL matches?
How to implement NGINX as a proxy with basic authorization headers added by URL match?
There is a server on which it is planned to deploy NGINX, let it be localhost. I want to use it as a proxy, which, if the URL matches, will add a basic authorization header.
Example, using a proxy to open google.com and add header
Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l to the request
Answer the question
In order to leave comments, you need to log in
proxy_set_header
As a value, you can use text, variables, and their combinations.
If the value of the header field is an empty string, then the field will not be transmitted to the proxied server at all.
map $uri $a {
default "";
~^/some_uri "Basic YWxhZGRpbjpvcGVuc2VzYW1l";
}
proxy_set_header Authorization $a;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question