views:

42

answers:

1

My nginx.conf file is getting larger and large with dozens of vhosts repeating the same lines over and over. I was wondering if there is anyway to declare the following globally without having to repeat them for each project:

# Route all requests for non-existent files to index.php
if (!-e $request_filename) {
 rewrite ^(.*)$ /index.php/$1 last;
}

location ~ \.php($|/) {
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_pass 127.0.0.1:9000;
}
+1  A: 

Create a file with the common setup for your vhosts (ie. vhost.conf). Wherever you would like to utilize this common setup, just include that vhost.conf-file.

server {
    include vhost.conf

    location /test {
        # Custom setup for /test
    }
}

Paths are relative to your nginx.conf-file, use absolute paths if specifying vhost.conf outside your nginx.conf-path. http://wiki.nginx.org/NginxHttpMainModule#include

xintron
you saved the day
Xeoncross