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 2012-10-28 05:00
on 2012-10-28 05:35
On 10/27/12 11:59 PM, Quintin Par 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. http://nginx.org/en/docs/http/ngx_http_core_module...
on 2012-10-28 11:25
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 2012-10-28 15:38
On 28 October 2012 03:59, Quintin Par <quintinpar@gmail.com> 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 http://nginx.org/r/location and http://wiki.nginx.org/HttpCoreModule#location I find the wiki documentation on this specific topic to be clearer and more useful. Jonathan -- Jonathan Matthews // Oxford, London, UK http://www.jpluscplusm.com/contact.html
on 2012-10-28 15:41
On 28 October 2012 10:25, Quintin Par <quintinpar@gmail.com> 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. http://bit.ly/RdVWFo (A mailing list is not the place to ask *trivially* answerable questions!) Jonathan -- Jonathan Matthews // Oxford, London, UK http://www.jpluscplusm.com/contact.html
on 2012-10-29 05:20
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 Matthews
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.