How to apply the same rules to several locations with Nginx?

Solution 1:

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.