I currently have 3 nginx configuration files for 2 server blocks in the standard file paths:
/usr/local/etc/nginx/nginx.conf
/usr/local/etc/nginx/sites-available/one.website.com
/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;
#}
}
Best Answer
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:
sed
ormake
scripts to generate the configuration files.