Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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;
    server_name site1.domain.co.uk;

    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.

Thanks.

share|improve this question

1 Answer 1

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

 
discard

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.