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 currently have 3 nginx configuration files for 2 server blocks in the standard file paths:

  1. /usr/local/etc/nginx/nginx.conf
  2. /usr/local/etc/nginx/sites-available/
  3. /usr/local/etc/nginx/sites-available/

The nginx.conf includes all files in /usr/local/etc/nginx/sites-enabled/* which have symlinks to the two websites in sites-available folder.

Both websites serve PHP files and the only difference between the two config files are

fastcgi_param PHP_VALUE "error_log=...

What is the best practice to consolidate the two website config files?

Here is the full config on one of them (note that setting the PHP error_log value is related to the nginx error_log):

server {
    listen 80;
    access_log /usr/local/var/log/;
    error_log  /usr/local/var/log/;
    root /Users/hobbes3/Scripts/Neadwerx/;

    location / {
        index index.html index.htm index.php;
        autoindex on;

    # Disable favicon.ico logging
    location = /favicon.ico {
        log_not_found off;
        access_log off;

    # Enable permalink structures
    if (!-e $request_filename) {
        rewrite . /index.php last;

    location ~ \.php$ {
        try_files $uri = 404;
        include /usr/local/etc/nginx/fastcgi_params;
        fastcgi_pass; # 9000 for xdebug
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/usr/local/var/log/";

    # Disable static content logging and set cache time to max
    location ~* ^.+.(jpg|jpeg|gif|png|css|js|ico|xml|html|htm|txt)$ {
        access_log off;
        log_not_found off;
        expires max;

    # Deny access to htaccess and htpasswd files
    location ~ /\.ht {
        deny  all;

    # Deny access to hidden files (beginning with a period)
    #location ~ /\. {
    #    access_log off; log_not_found off; deny all;
share|improve this question
up vote 2 down vote accepted

nginx's official line on this is no, we like our configurations unwieldy and full of redundancies; mainly because it's faster and their focus is on speed. They recommend using either:

  • includes in each of your files under sites-configured that point to a common configuration file. Your distro probably didn't account for this when they created their folder structure, so you'll likely have to create something yourself.
  • external configuration generation mechanism like a set of sed or make scripts to generate the configuration files.
share|improve this answer
Thanks, it's good to hear from the developer's point of view. – hobbes3 Apr 15 '13 at 4:16

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.