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 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/one.website.com
  3. /usr/local/etc/nginx/sites-available/two.website.com

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

server_name
access_log
error_log
root
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;
    server_name one.website.com;
    access_log /usr/local/var/log/one.website.com-access.log;
    error_log  /usr/local/var/log/one.website.com-error.log;
    root /Users/hobbes3/Scripts/Neadwerx/one.website.com;

    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 127.0.0.1:9001; # 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/one.website.com-error.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

1 Answer 1

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

 
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.