I’m currently trying to make a template for future virtual hosts. To
minimize the amount of editing required i am using $server_name in some
parts of the template.
For example:
server_name example.com
access_log /var/log/www/$server_name-access combined;
error_log /var/log/www/$server_name-error error;
While it works great for access_log directive(logfile is named
example.com-access), error log file name is, actually
$server_name-error.
I’m running nginx 1.0.6
On Fri, Sep 23, 2011 at 06:52:50AM -0400, Hety wrote:
Why its supports it in access_log then? I fail to see logic here.
Access log is quite different as it’s only needed/used during
http request processing. On the other hand, error_log is global thing
and used even if no http requests exists, e.g. to log signals and
various other internal actions. It’s not possible to use
variables which are only exists in http request context to log
internal actions.
And again (this tends to be a FAQ):
You shouldn’t use variables to shorten configs by storing static
strings in them. Variables are evaluated at run-time during
request process, they are costly compared to static strings. You
need some macro expansion instead. Right now it may be done via
external tools, e.g. sed + make will do (as well as any other
template mechanism).