# Passing variables to access\_log, error\_log names

**URL:** <https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771>\
**Category:** NGINX\
**Created:** [February 26, 2011, 10:51pm UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771 "2011-02-26T22:51:31Z")\
**Posts on this page:** 10\
**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:** [February 26, 2011, 10:51pm UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/1 "2011-02-26T22:51:31Z")

</div>

Hello,

I am configuring an automagic virtual hosting on my private machine, to  
serve myself projects which I currently work on. Configuration I’m using  
is like this:

server {  
listen 80;  
server\_name ~^(www.)?(?P[^.]+).mydomain.com$;  
root /home/ajgon/htdocs/$project;  
access\_log /var/log/nginx/$project.mydomain.com.access\_log main;  
error\_log /var/log/nginx/$project.mydomain.com.error\_log info;  
include lang/php;  
}

Everything is working as expected - except one thing. I’m getting two  
log files with following names:  
/var/log/nginx/$project.mydomain.com.access\_log  
/var/log/nginx/$project.mydomain.com.error\_log  
for any Vhost.

Is there any sollution to make nginx parse the variable and set proper  
log name?

Greets from Poland and thank you for any help!

Posted at Nginx Forum:

> **[Passing variables to access\_log, error\_log names](https://forum.nginx.org/read.php?2,178665,178665#msg-178665)**
>
> Hello, I am configuring an automagic virtual hosting on my private machine, to serve myself projects which I currently work on. Configuration I'm using is like this: server { listen 80; server\_name ~^(www\\.)?(?P\<project\>\[^.\]+).mydomain.com$;

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 26, 2011, 10:56pm UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/2 "2011-02-26T22:56:31Z")

</div>

Where are you setting $project?

Regards,  
Richard K.

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 26, 2011, 11:10pm UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/3 "2011-02-26T23:10:18Z")

</div>

Hmm… strange - in my post, I see this line correctly, but in your  
reply project part is broken - maybe something with HTML escaping…  
anyway, the server\_name line should look like this:  
server\_name ~^(www.)?(?P[^.]+).mydomain.com$;  
server\_name ~^(www.)?(?P\<project\>[^.]+).mydomain.com$; (entitied  
version)

I’m basically cathing this variable in regexp while parsing  
server\_name.

Greets

Posted at Nginx Forum:

> **[Re: RE: Passing variables to access\_log, error\_log names](https://forum.nginx.org/read.php?2,178665,178672#msg-178672)**
>
> Hello, I am configuring an automagic virtual hosting on my private machine, to serve myself projects which I currently work on. Configuration I'm using is like this: server { listen 80; server\_name ~^(www\\.)?(?P\<project\>\[^.\]+).mydomain.com$;

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 27, 2011, 12:03am UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/4 "2011-02-27T00:03:30Z")

</div>

Hello!

On Sat, Feb 26, 2011 at 04:49:48PM -0500, ajgon wrote:

> Hello,
> 
> I am configuring an automagic virtual hosting on my private machine, to  
> serve myself projects which I currently work on. Configuration I’m using  
> is like this:
> 
> server {  
> listen 80;  
> server\_name ~^(www.)?(?P[^.]+).mydomain.com$;

Just a side note: forum is still eating data (originally  
“P” was here), you may want to consider using mailing  
list directly instead.

> for any Vhost.
> 
> Is there any sollution to make nginx parse the variable and set proper  
> log name?

There is no variables support in error\_log directive (and it’s  
unlikely to appear), so “…error\_log” file is expected. Use  
common error\_log for all vhosts instead.

Variables in access\_log should work as of 0.7.4+. On the other  
hand, named captures in regular expressions only supported in  
0.8.25+. Are you sure you see “…access\_log” file? Which  
version you are using?

Maxim D.

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 26, 2011, 11:19pm UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/5 "2011-02-26T23:19:04Z")

</div>

On 26 Fev 2011 21h49 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> access\_log /var/log/nginx/$project.mydomain.com.access\_log main;  
> proper log name?  
> I know that this will work:

access\_log /var/log/nginx/$project/mydomain.com.access\_log main;  
error\_log /var/log/nginx/$project/mydomain.com.error\_log info;

Placing the variable in the filename doesn’t AFAIK.

— appa

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 27, 2011, 9:19am UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/6 "2011-02-27T09:19:11Z")

</div>

On Feb 27, 2011, at 2:39 , Antnio P. P. Almeida wrote:

> > > on. Configuration I’m using is like this:  
> > > access\_log /var/log/nginx/$project.mydomain.com.access\_log main;  
> > > proper log name?  
> > > I just tried:  
> > > access\_log /var/log/nginx/$test/domain\_access.log;  
> > > nginx workers must have rights to create files in /var/log/nginx.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 27, 2011, 12:46am UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/7 "2011-02-27T00:46:03Z")

</div>

On 26 Fev 2011 23h01 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > server {  
> > include lang/php;  
> > There is no variables support in error\_log directive (and it’s  
> > unlikely to appear), so “…error\_log” file is expected. Use  
> > common error\_log for all vhosts instead.
> 
> Variables in access\_log should work as of 0.7.4+. On the other  
> hand, named captures in regular expressions only supported in  
> 0.8.25+. Are you sure you see “…access\_log” file? Which  
> version you are using?

I just tried:

set $test foo;  
access\_log /var/log/nginx/$test.domain\_access.log;  
error\_log /var/log/nginx/domain\_error.log;

And no access log entry is registered whatsoever. I’m using 0.9.4.

Can you elaborate on your ‘Variables in access\_log should work’?  
Do you mean it should work in a dirname and not on a filename? E.g.:

access\_log /var/log/nginx/$test/domain\_access.log;

Thank you,  
— appa

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 27, 2011, 5:29pm UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/8 "2011-02-27T17:29:21Z")

</div>

## Maxim D. Wrote:

> > server {  
> > listen 80;  
> > server\_name ~^(www.)?(?P[^.]+).mydomain.com$;
> 
> Just a side note: forum is still eating data  
> (originally  
> “P” was here), you may want to consider using  
> mailing  
> list directly instead.

Unfortunately, the mailing list is not as user friendly for me as the  
forum.

I note that the forum module being used has the option to strip HTML and  
BB Code tags which must be activated.

I wonder if the forum admin would consider switching it off.

I also wonder if he will get round to looking at my suggestion for  
dealing with the problem with the preview setting which disrupts  
navigating the forum.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,178665,178838#msg-178838](http://forum.nginx.org/read.php?2,178665,178838#msg-178838)

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 27, 2011, 6:03pm UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/9 "2011-02-27T18:03:16Z")

</div>

On 27 Fev 2011 08h17 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > E.g.:
> > 
> > access\_log /var/log/nginx/$test/domain\_access.log;
> 
> nginx workers must have rights to create files in /var/log/nginx.

They have. If I set:

access\_log /var/log/nginx/foo.domain\_access.log;  
error\_log /var/log/nginx/domain\_error.log;

a new access log file is created. It just happens that with the above  
setting of $set foo no foo.domain\_access.log file is created.

— appa

---

<div class="post-metadata">

**Author:** ![ajgon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajgon](https://www.ruby-forum.com/u/ajgon)\
**Post date:** [February 27, 2011, 12:21am UTC](https://www.ruby-forum.com/t/passing-variables-to-access-log-error-log-names/203771/10 "2011-02-27T00:21:37Z")

</div>

Ok, now that you mentioned it, silly me… yes I don’t see any  
access\_log files connected to this rule. There is only  
$project.mydomain.com.error\_log file.

I’m using nginx 0.8.53.

So basically - it is not possible? It’s not a big deal anyway, I can  
always keep them in one file and grep them or whatever… I was just  
wondering that, maybe I am doing something wrong.

Greets!

Posted at Nginx Forum:

> **[Re: RE: Passing variables to access\_log, error\_log names](https://forum.nginx.org/read.php?2,178665,178688#msg-178688)**
>
> Hello, I am configuring an automagic virtual hosting on my private machine, to serve myself projects which I currently work on. Configuration I'm using is like this: server { listen 80; server\_name ~^(www\\.)?(?P\<project\>\[^.\]+).mydomain.com$;
