# Newbie Question: Sharing proxy\_pass config between locations

**URL:** <https://www.ruby-forum.com/t/newbie-question-sharing-proxy-pass-config-between-locations/217627>\
**Category:** NGINX\
**Created:** [March 6, 2012, 11:21pm UTC](https://www.ruby-forum.com/t/newbie-question-sharing-proxy-pass-config-between-locations/217627 "2012-03-06T23:21:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 6, 2012, 11:21pm UTC](https://www.ruby-forum.com/t/newbie-question-sharing-proxy-pass-config-between-locations/217627/1 "2012-03-06T23:21:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Cabbar\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e495f1/32.png) [@Cabbar\_D](https://www.ruby-forum.com/u/Cabbar_D)\
**Post date:** [March 6, 2012, 11:39pm UTC](https://www.ruby-forum.com/t/newbie-question-sharing-proxy-pass-config-between-locations/217627/2 "2012-03-06T23:39:06Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Cabbar\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e495f1/32.png) [@Cabbar\_D](https://www.ruby-forum.com/u/Cabbar_D)\
**Post date:** [March 7, 2012, 10:04am UTC](https://www.ruby-forum.com/t/newbie-question-sharing-proxy-pass-config-between-locations/217627/3 "2012-03-07T10:04:16Z")

</div>

This makes sense.

Thanks.
