11

I'd like to configure several paths within a site (such as /foo/ and /bar/) in the same way. To avoid copy-pasting, I figured I should use a single location block, but the only way I found for doing that is to use a regex, such as:

location ~ ^/(foo|bar)/ {
    ...
}

Is this the best way or is there a better alternative?

0

1 Answer 1

5

This would work, but I believe it works slower, because it involves a regex engine, another alternative you could create the config you want in a separate file and include them in each location so that it would be written once and could be edited all together, like this

location /foo {
    include foo.conf;
}
location /bar {
    include foo.conf;
}

Inside foo.conf you could write any config that's in a location scope
heres a random sample snippet:

root /foo/bar;
try_files $uri /index.html;
Sign up to request clarification or add additional context in comments.

2 Comments

Interesting idea, but that means splitting the config into 2 or more separate files. I guess it could be worth doing for a very busy site, if it provides a measurable performance improvement.
also im not sure it will allow two roots, might need alias for the 2nd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.