|
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. ?
_______________________________________________ nginx mailing list [hidden email] http://mailman.nginx.org/mailman/listinfo/nginx |
|
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.html#location -- Barry Abrahamson | Systems Wrangler | Automattic Blog: http://barry.wordpress.com _______________________________________________ nginx mailing list [hidden email] http://mailman.nginx.org/mailman/listinfo/nginx |
|
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? - QuintinOn Sun, Oct 28, 2012 at 10:05 AM, Barry Abrahamson <[hidden email]> wrote:
_______________________________________________ nginx mailing list [hidden email] http://mailman.nginx.org/mailman/listinfo/nginx |
|
In reply to this post by Quintin Par
On 28 October 2012 03:59, Quintin Par <[hidden email]> 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 _______________________________________________ nginx mailing list [hidden email] http://mailman.nginx.org/mailman/listinfo/nginx |
|
In reply to this post by Quintin Par
On 28 October 2012 10:25, Quintin Par <[hidden email]> 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 _______________________________________________ nginx mailing list [hidden email] http://mailman.nginx.org/mailman/listinfo/nginx |
|
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 <[hidden email]> wrote:
_______________________________________________ nginx mailing list [hidden email] http://mailman.nginx.org/mailman/listinfo/nginx |
| Powered by Nabble | Edit this page |
