proxy_set_header on HTTP or Server level

classic Classic list List threaded Threaded
3 messages Options
xrd
Reply | Threaded
Open this post in threaded view
|

proxy_set_header on HTTP or Server level

xrd
Hello,

We recently made some order in our configuration to make it cleaner and
readable.
We have moved all reverse proxy related parameters on the HTTP level from
the vhosts locations:
----
  proxy_set_header X-Forwarded-Host $host;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_read_timeout 65;
  proxy_send_timeout 65;
  proxy_connect_timeout 30;
  proxy_buffering off;
  proxy_buffers 8 64k;
  proxy_buffer_size 64k;
  proxy_busy_buffers_size 128k;
  proxy_http_version 1.1;
  proxy_intercept_errors off;
----
As a result we got some issue with the at leas some of them:
----
  proxy_set_header X-Forwarded-Host $host;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
----
As per documentation -
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header:
Context: http, server, location

> These directives are inherited from the previous level if and only if
there are no proxy_set_header directives defined on the current level.
Does it mean that if at least one of the proxy_set_header is defined on
location level we should define all other on this level because it broke
inheritance?

Per our experience, these directives only work on location level. They do
not apply when we set them up on HTTP or Server level.

Why may be wrong with our configuration?

Thank you!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285462,285462#msg-285462

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: proxy_set_header on HTTP or Server level

Francis Daly
On Fri, Aug 30, 2019 at 01:03:57PM -0400, stmx38 wrote:

Hi there,

> As per documentation -
> http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header:
> Context: http, server, location
>
> > These directives are inherited from the previous level if and only if
> there are no proxy_set_header directives defined on the current level.

> Does it mean that if at least one of the proxy_set_header is defined on
> location level we should define all other on this level because it broke
> inheritance?

Yes, that is what it means.

The request is handled in a location{}, with proxy_pass.

If there is any proxy_set_header in that location{}, then only those
proxy_set_header values are used.

If not, then if there is any proxy_set_header in the surrounding server{},
then only those proxy_set_header values are used.

If not, then if there is any proxy_set_header in the surrounding http{},
then only those proxy_set_header values are used.

In the same way, if "proxy_busy_buffers_size" is set in the location{},
that value is used; if not, if "proxy_busy_buffers_size" is set in the
server{}, that value is used; if not, if "proxy_busy_buffers_size" is set
in http{}, that value is used.


In general in nginx (with a few exceptions) directive inheritance is
"not at all", or "by replacement".

> Per our experience, these directives only work on location level. They do
> not apply when we set them up on HTTP or Server level.
>
> Why may be wrong with our configuration?

Can you show a sample configuration, if there is a problem?

But if it has "proxy_set_header" in the location{}, then any
proxy_set_header outside that location is irrelevant for this request.

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
xrd
Reply | Threaded
Open this post in threaded view
|

Re: proxy_set_header on HTTP or Server level

xrd
Francis,

Basically, the issue was with the 'proxy_set_header' directives. In such
cases, when we define at least one in the location, we should also define
all the rests headers.

From your reply, I understand that with the
'proxy_read_timeout/proxy_send_timeout' we should not have such situations.


Thank you for your reply and explanation!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285462,286420#msg-286420

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx