Nginx shared directives

Tigra asked:

Moving now from apache to nginx, also rewriting .htaccess to nginx.
I have such “problem”:

I have about ten sites, that utilize same core.
So I have a bunch of rewrite rules that should go to each of one of them.
Moreover, number of sites will be added, as well as number of common rules.

In apache i’ve used to write all common directives to global /www folder when all websites are placed.

But for now, in nginx i cant determine how should i organize config file.

I have about 10 common rules and 30 per-site rules for every site.

So have no idea, how to NOT to write 10 common rules to each config and in the same time to provide each site with his own rules.

Thanks in advance.

My answer:

You can create a new file in /etc/nginx containing your shared directives, and then include them in each site’s configuration.

The config files which ship with nginx include an example of this: fastcgi_params contains shared directives that are used in various configuration files where they call include fastcgi_params;.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.