Passing variables to access_log, error_log names

Igor Sysoev igor at sysoev.ru
Sun Feb 27 11:17:19 MSK 2011


On Feb 27, 2011, at 2:39 , António P. P. Almeida wrote:

> On 26 Fev 2011 23h01 WET, mdounin at mdounin.ru wrote:
> 
>> 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<project>" was here), you may want to consider using mailing 
>> list directly instead.
>> 
>>> 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?
>> 
>> 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;

nginx workers must have rights to create files in /var/log/nginx.
 

--
Igor Sysoev
http://sysoev.ru/en/




More information about the nginx mailing list