Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have split my sites up into different configuration files to keep things more organised. This also allows me to take out individual config files and make sites unavailable.

My config file for each site looks like this:

server {
    listen 80;

    root /var/www/php/site1;

    location / {
        index index.html index.php;
        try_files $uri $uri/ /index.php;

    location ~ \.php$ {
        try_files $uri /index.php;
        fastcgi_pass        php;
        include             fastcgi_params;
        fastcgi_param       PATH_INFO $fastcgi_script_name;
            fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;

    location  /common {
        alias  /var/www/common;

My question is, do I have to repeat the location blocks for every site? Or can I add a new server block that will match everything? If this is possible, would it conflict with my config file that matches all domains that are not mapped to a site? This config file looks like this:

server {
    listen 80 default_server;
    server_name _;
    return 404;

Or, am I going about this all wrong? Although not the main purpose of this question, if anyone could tell me of any major mistakes in my config, that would be great.


share|improve this question
up vote 3 down vote accepted

If you want to keep separate config files per host, but have some parts of configuration the same between each, then you probably want to use include.

In the server block of the per-site file:

include /path/to/common-configs.conf;

..and have that file contain the location blocks.

share|improve this answer
Ah of course, that makes a lot of sense. Not sure why I didn't think of something so obvious! Thanks. – SteveEdson Jan 2 '13 at 11:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.