Newbie Question: Sharing proxy_pass config between locations

Hi,

I have a basic configuration that points to a back-end server with
proxy_pass and bunch of proxy_set_header call entries. And, I have
multiple locations entries that keep doing the same thing, e.g.

    location / {
            proxy_pass              http://127.0.0.1:5000
            proxy_set_header        X-Real-IP $remote_addr;
            ... more proxy_set headers
    }

    location /x/ {
            access_log off
            proxy_pass              http://127.0.0.1:5000
            proxy_set_header        X-Real-IP $remote_addr;
            ... more proxy_set headers
    }

Is it possible to define this proxy_pass & proxy_set_headers once, and
share it between these locations? Or, do I need to keep doing this for
all?

Thanks.

On Wed, Mar 07, 2012 at 12:21:06AM +0200, Cabbar D. wrote:

Hi there,

Is it possible to define this proxy_pass & proxy_set_headers once, and
share it between these locations? Or, do I need to keep doing this for
all?

One option is to put some or all of the common configuration into an
external file, and “include” it in the appropriate location blocks.

Another option is to put all of the proxy_set_header lines directly in
server{}, outside of any location{} so that they will be inherited into
all of them. Then put the proxy_pass into the locations that matter.

Be aware of what happens if you want things slightly different in one
location{}, though – if you wish to add an extra proxy_set_header,
the two options have different requirements.

f

Francis D. [email protected]

This makes sense.

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs