# $server\_name in error\_log logfile name

**URL:** <https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071>\
**Category:** NGINX\
**Created:** [September 21, 2011, 2:40pm UTC](https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071 "2011-09-21T14:40:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 21, 2011, 2:40pm UTC](https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071/1 "2011-09-21T14:40:36Z")

</div>

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](http://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:

> **[$server\_name in error\_log logfile name](https://forum.nginx.org/read.php?2,215503,215503#msg-215503)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![Hety](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@Hety](https://www.ruby-forum.com/u/Hety)\
**Post date:** [September 21, 2011, 3:32pm UTC](https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071/2 "2011-09-21T15:32:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hety](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@Hety](https://www.ruby-forum.com/u/Hety)\
**Post date:** [September 22, 2011, 7:18pm UTC](https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071/3 "2011-09-22T19:18:05Z")

</div>

As far as I know, Nginx does not support variable in error\_log.

Posted at Nginx Forum:

> **[Re: $server\_name in error\_log logfile name](https://forum.nginx.org/read.php?2,215503,215647#msg-215647)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![Hety](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@Hety](https://www.ruby-forum.com/u/Hety)\
**Post date:** [September 23, 2011, 1:19pm UTC](https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071/4 "2011-09-23T13:19:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hety](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@Hety](https://www.ruby-forum.com/u/Hety)\
**Post date:** [September 23, 2011, 1:59pm UTC](https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071/5 "2011-09-23T13:59:11Z")

</div>

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

Posted at Nginx Forum:

> **[Re: $server\_name in error\_log logfile name](https://forum.nginx.org/read.php?2,215503,215713#msg-215713)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![Hety](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@Hety](https://www.ruby-forum.com/u/Hety)\
**Post date:** [September 23, 2011, 12:53pm UTC](https://www.ruby-forum.com/t/server-name-in-error-log-logfile-name/212071/6 "2011-09-23T12:53:37Z")

</div>

Why its supports it in access\_log then? I fail to see logic here.

Posted at Nginx Forum:

> **[Re: $server\_name in error\_log logfile name](https://forum.nginx.org/read.php?2,215503,215702#msg-215702)**
>
> 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...
