Multiple URL parameters in the same location directive

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. ?

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

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

On 28 October 2012 03:59, Quintin P. [email protected] 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 and
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
http://www.jpluscplusm.com/contact.html

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.

On 28 October 2012 10:25, Quintin P. [email protected] 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 - Let Me Google That For You

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

Jonathan

Jonathan M. // Oxford, London, UK
http://www.jpluscplusm.com/contact.html