5

In a project I have very large nginx configuration with a lot of redundant lines.

The current state is like the following

location ~ /loc1/ {
    common rules;
}
location ~ /some/other/location/ {
    common rules;
}
location ~ /yet/anotherone {
    common rules;
}

etc .....

What I'd like to have is seperated way where there is a generic rule template and a list of locations.

In other related questions people have used regex to match several locations like so

location ~ (/loc1/|/some/other/location/|/yet/anotherone) {
    common rules;
}

In my case this would result in a huge line which would be very ugly to maintain.

Is there another cleaner way to do this?

Thank you very much.

PhilippN
  • 63
  • 1
  • 3

1 Answers1

4

First option is to put common rules; into file and include that file.

Another one is depend on what's exactly in that rules. In many cases you could move them to upper level like:

common rules;

location /a {
}

location /b/whatever {
}

and they will be inherited.

Alexey Ten
  • 8,435
  • 1
  • 34
  • 36