# How to set a option within a location block

**URL:** <https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190>\
**Category:** NGINX\
**Created:** [July 7, 2010, 11:07am UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190 "2010-07-07T11:07:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 11:07am UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/1 "2010-07-07T11:07:21Z")

</div>

Hi,

I have the URL [.xyz Domain Names | Join Generation XYZ](http://www.xyz.com/dav/xxx) and I need to be able to set  
http\_timeout only when /dav/ is present in the URL. The problem is that  
the configuration is third party supplied and they already have:

location /  
{

}

So is it possible to have a location within a location for something  
like:

## location / { location ^~ /dav/ { keepalive\_timeout 0; } }

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 11:13am UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/2 "2010-07-07T11:13:13Z")

</div>

Hello!

On Wed, Jul 7, 2010 at 1:06 PM, --[UxBoD]-- [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So is it possible to have a location within a location for something like:
> 
> location /  
> {  
> location ^~ /dav/ {  
> keepalive\_timeout 0;  
> }  
> }  
> Yes, it is possible.  
> You can even have such configuration:  
> location /  
> {  
> … all configuration …  
> location /dav  
> {  
> keepalive\_timeout 0;  
> }  
> }

–  
Boris D..

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 11:20am UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/3 "2010-07-07T11:20:50Z")

</div>

----- Original Message -----

> > Â Â Â Â keepalive\_timeout 0;  
> > }  
> > }

## Thanks Boris, if the last command is a proxy\_redirect and I add that block after it will it be processed ?

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 11:26am UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/4 "2010-07-07T11:26:06Z")

</div>

On Wed, Jul 7, 2010 at 1:19 PM, --[UxBoD]-- [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thanks Boris, if the last command is a proxy\_redirect and I add that block after it will it be processed ?  
> If you mean, that you will have configuration,

location /  
{  
… some configuration …  
proxy\_redirect …;  
location /svn  
{  
keepalive\_timeout 0;  
}  
}

Than it is absolutely correct.

–  
Boris D..

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 12:14pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/5 "2010-07-07T12:14:07Z")

</div>

----- Original Message -----

> > {  
> > }  
> > }
> 
> ?

## Would need to duplicate all the other options within the /dav/ block as once it matches it does not process the other location block.

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 11:40am UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/6 "2010-07-07T11:40:45Z")

</div>

On Wed, Jul 07, 2010 at 10:06:16AM +0100, --[UxBoD]-- wrote:

> location /  
> {  
> location ^~ /dav/ {  
> keepalive\_timeout 0;  
> }  
> }

It’s possible, but why can not you add

location /dav/ {  
}

before or after

location / {  
}

?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 12:23pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/7 "2010-07-07T12:23:29Z")

</div>

On Wed, Jul 07, 2010 at 11:12:42AM +0100, --[UxBoD]-- wrote:

> > > location /  
> > > keepalive\_timeout 0;  
> > > location / {  
> > > }
> > 
> > ?
> 
> Would need to duplicate all the other options within the /dav/ block as once it matches it does not process the other location block.

You may move common directives outside “location /”:

common all directives

location / {  
}

location /dav/ {  
}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 12:15pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/8 "2010-07-07T12:15:17Z")

</div>

----- Original Message -----

> location /svn  
> {  
> keepalive\_timeout 0;  
> }  
> }
> 
> Than it is absolutely correct.

## Odd as that completely broke the installation ☹ Have had to move the keepalive outside of the block for the time being. Will do more testing.

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 1:23pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/9 "2010-07-07T13:23:13Z")

</div>

----- Original Message -----

> > > > problem  
> > > > something
> > 
> > Would need to duplicate all the other options within the /dav/ block  
> > }

## Igor, to be clear on the flow then that would process all the directives under ‘/’ and then if the URI contains /dav/ it would also pull in what ever is in that location block; in essence inherit all the directives ?

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 1:26pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/10 "2010-07-07T13:26:44Z")

</div>

On Wed, Jul 07, 2010 at 12:22:02PM +0100, --[UxBoD]-- wrote:

> > > > > set http\_timeout only when /dav/ is present in the URL. The  
> > > > > So is it possible to have a location within a location for  
> > > > > It’s possible, but why can not you add
> > 
> > location /dav/ {  
> > }
> 
> Igor, to be clear on the flow then that would process all the directives under ‘/’ and then if the URI contains /dav/ it would also pull in what ever is in that location block; in essence inherit all the directives ?

No, please read this:

> **[How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration)**
>
> nginx first decides which server should process the request. Let’s start with a simple configuration where all three virtual servers listen on port \*:80:

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 1:36pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/11 "2010-07-07T13:36:07Z")

</div>

On Wed, Jul 07, 2010 at 12:29:58PM +0100, --[UxBoD]-- wrote:

> > > > > > > {  
> > > > > > > keepalive\_timeout 0;  
> > > > > > > location / {  
> > > > > > > common all directives  
> > > > > > > also pull in what ever is in that location block; in essence inherit  
> > > > > > > all the directives ?
> > 
> > No, please read this:  
> > [How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration)
> 
> Ah okay 🙂 Thank you Igor that answers the question; will have to duplicate directives within the /dav/ like the / literal but also include the timeout. Is there any other way to include a specific directive without duplication ?

You may move them on upper level: server or http.  
Or you may move them to a file and include the file.

However, I prefer to put all directives explicitly, this allows to  
create  
scaleable configurations.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 2:18pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/12 "2010-07-07T14:18:51Z")

</div>

----- Original Message -----

> > > > > > > wrote:
> > > > > > > 
> > > > > > > > is that the configuration is third party supplied and  
> > > > > > > > for  
> > > > > > > > It’s possible, but why can not you add
> > > > > 
> > > > > location / {  
> > > > > all the directives ?
> 
> You may move them on upper level: server or http.  
> Or you may move them to a file and include the file.
> 
> However, I prefer to put all directives explicitly, this allows to  
> create  
> scaleable configurations.

Hi Igor, appreciate all the help you have provided. I think we shall  
need to leave it within the server section; which is a pity as it will  
apply to every URI eg:

> **[Redirecting…](https://www.xyz.com/contacts)**

> **[Redirecting…](https://www.xyz.com/dav)**

## where it would have been great for it to only apply to /dav; but the literal location contains lots and lots of directives and I would hate to duplicate them all into a separate location block.

Thanks, Phil

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/13 "2010-07-07T14:24:07Z")

</div>

On Wed, Jul 7, 2010 at 7:18 PM, --[UxBoD]-- [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## where it would have been great for it to only apply to /dav; but the literal location contains lots and lots of directives and I would hate to duplicate them all into a separate location block.

use include ?

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![SSS\_UxBoD\_S-S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@SSS\_UxBoD\_S-S](https://www.ruby-forum.com/u/SSS_UxBoD_S-S)\
**Post date:** [July 7, 2010, 1:30pm UTC](https://www.ruby-forum.com/t/how-to-set-a-option-within-a-location-block/191190/14 "2010-07-07T13:30:50Z")

</div>

----- Original Message -----

> > > > > > I have the URL [Redirecting…](http://www.xyz.com/dav/xxx) and I need to be
> > > > > > 
> > > > > > ```
> > > > > > }
> > > > > > 
> > > > > > ```
> > > > > 
> > > > > }
> > 
> > all the directives ?
> 
> No, please read this:  
> [How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration)

## Ah okay 🙂 Thank you Igor that answers the question; will have to duplicate directives within the /dav/ like the / literal but also include the timeout. Is there any other way to include a specific directive without duplication ?

Thanks, Phil
