我目前在标准文件path中有2个服务器块的nginxconfiguration文件:
/usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/sites-available/one.website.com /usr/local/etc/nginx/sites-available/two.website.com nginx.conf包含/usr/local/etc/nginx/sites-enabled/*中的所有文件,这些文件与sites-available文件夹中的两个网站有符号链接。
这两个网站都提供PHP文件,两个configuration文件之间的唯一区别是
server_name access_log error_log root fastcgi_param PHP_VALUE "error_log=...
巩固两个网站configuration文件的最佳做法是什么?
这里是其中一个完整的configuration(请注意,设置PHP error_log值与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; #} }
nginx对此的官方说法是否定的,我们喜欢我们的configuration笨拙和充满冗余 ; 主要是因为速度更快,重点更高。 他们build议使用:
sed或make脚本来生成configuration文件。