# Multiple URL parameters in the same location directive

**URL:** <https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048>\
**Category:** NGINX\
**Created:** [October 28, 2012, 5:00am UTC](https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048 "2012-10-28T05:00:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 28, 2012, 5:00am UTC](https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048/1 "2012-10-28T05:00:14Z")

</div>

Hi all,

I have some URL patterns that follow the same directive specifications.

E.g. sitemap.xml, robots.txt etc. follow the same location directive  
with  
the same caching policy, invalidation etc.

```
    location /robots.txt {

        proxy_pass http://localhost:82;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For 

```

$proxy\_add\_x\_forwarded\_for;

```
        proxy_set_header Accept-Encoding "";

        proxy_ignore_headers Cache-Control;

        proxy_ignore_headers Expires;

        proxy_ignore_headers X-Accel-Expires;

        proxy_cache cache;

        proxy_cache_key $scheme$host$request_uri;

        proxy_cache_valid 200 302 2m;

        proxy_cache_use_stale updating;

    }

```

Now I have written separate directives for all of these URL patterns.

How can I combine them into one line?

Can I do this?

```
    location /robots.txt, sitemap.xml, ~*.xml {

```

etc. ?

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 28, 2012, 5:35am UTC](https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048/2 "2012-10-28T05:35:52Z")

</div>

On 10/27/12 11:59 PM, Quintin P. wrote:

> How can I combine them into one line?

You _could_ combine them into one line using a regex, but I would not  
recommend it - it will be more complicated to maintain over time and  
less readable. I would recommend putting all of your common  
configuration directives into a separate file and including it in each  
individual location block. Something like this:

location = /robots.txt {  
include common-config.conf;  
}

location = /sitemap.xml {  
include common-config.conf;  
}

…

I would also be sure to read the documentation on location syntax [0] to  
understand the differences between exact, prefix, and regex matches so  
you are sure to use the correct type for each pattern you are trying to  
match.

Hope this is useful.

References:  
0. [Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#location)

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 28, 2012, 11:25am UTC](https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048/3 "2012-10-28T11:25:45Z")

</div>

Is there a way I can specify this in the same file itself? I dont want  
to  
spread this out to multiple files.

Include a section?

- Quintin

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 28, 2012, 3:38pm UTC](https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048/4 "2012-10-28T15:38:07Z")

</div>

On 28 October 2012 03:59, Quintin P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> I have some URL patterns that follow the same directive specifications.

[snip]

> Now I have written separate directives for all of these URL patterns.  
> How can I combine them into one line?
> 
> Can I do this?  
> location /robots.txt, sitemap.xml, ~\*.xml {

Not quite.

You’ll need to use a regular expresion in your location, as detailed  
at [Module ngx\_http\_core\_module](http://nginx.org/r/location) and  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#location)

I find the wiki documentation on this specific topic to be clearer and  
more useful.

## Jonathan

Jonathan M. // Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 29, 2012, 5:20am UTC](https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048/5 "2012-10-29T05:20:11Z")

</div>

Thanks Jon. I was desperately looking for a way to include this in the  
same file and in my experience there are a lot of things like this that  
are  
not documented in the wiki elsewhere but Maxim, Sergey, Antonio etc.  
seem  
to know.

On Sun, Oct 28, 2012 at 8:10 PM, Jonathan M.

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 28, 2012, 3:41pm UTC](https://www.ruby-forum.com/t/multiple-url-parameters-in-the-same-location-directive/224048/6 "2012-10-28T15:41:03Z")

</div>

On 28 October 2012 10:25, Quintin P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a way I can specify this in the same file itself? I don’t want to  
> spread this out to multiple files.
> 
> Include a section?

Yes, you can. Here you go. [LMGTFY](http://bit.ly/RdVWFo)

(A mailing list is not the place to ask _trivially_ answerable  
questions!)

## Jonathan

Jonathan M. // Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**
