configuration of 1000's entries
Francis Daly
francis at daoine.org
Fri Sep 27 17:34:53 UTC 2013
On Fri, Sep 27, 2013 at 04:22:25AM -0700, Shaun Savage wrote:
Hi there,
None of what follows is tested by me. So double-check before committing
to anything :-)
> I have many "virtual" paths on one nginx server. What I mean by this is
> there can be many top level paths, where each one has a cookie, static
> files, and a upstream server. The way I am doing it now is just
> duplicate every path.
>
> Is there a way to do this 'faster' 'less writing' 'better'? I am
> expecting 1000's of entries.
Faster for you to write, or faster for nginx to read and process?
Less writing for you, or for your "turn this input file into an
nginx.conf" script?
It looks like you could either auto-generate the conf file, so that it
will be big; or keep it small by using a (probably, nested) "location"
with regex and named captures.
After you have both, you can test your workload on your hardware to see
if there is a significant benefit of one over the other to you.
Or you can just make one, and see if your workload on your hardware is
handled well enough, and stop if it is.
The examples here look like there is a regular pattern to them. Assuming
that holds for all, then a simple template / macro system that does
a string replacement should work -- you keep your "real config" as a
list of a1, a2, etc; then run the script to generate the fragment of
nginx.conf that can be pasted in or "include"d.
Or you could try something like
==
location / {
location ~ ^/(?<bit>[^/]*)/exe {
# your "exe" stuff goes here, with $bit = a1 or a2
}
location ~ ^/(?<bit>[^/]*) {
# your "static" stuff goes here, with $bit = a1 or a2
}
}
==
but even with that, you're likely to want to auto-generate the "upstream"
sections externally to nginx anyway.
(You'll need other top-level location{} blocks for anything that should
not match the pattern you have shown, such as /login.)
All the "alias" lines you've shown look equivalent to a single "root
/var/www" at server-level -- that might simplify things, depending on
what else you plan to use the server for.
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list