$server_name in error_log logfile name

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

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215503,215503#msg-215503

Hello!

On Wed, Sep 21, 2011 at 08:39:42AM -0400, Hety wrote:

example.com-access), error log file name is, actually
$server_name-error.
I’m running nginx 1.0.6

The “error_log” directive doesn’t support variables.

Addtionally, this is not intended use of variables. They are
run-time and evaluated for each request. You want to use some
config generator instead.

Maxim D.

As far as I know, Nginx does not support variable in error_log.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215503,215647#msg-215647

Hello!

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).

Maxim D.

Thanks. Point taken. Will go RTFMmore and will try to avoid stupid
questions in future :slight_smile:

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215503,215713#msg-215713

Why its supports it in access_log then? I fail to see logic here.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215503,215702#msg-215702

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs