Passing variables to access_log, error_log names

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:
http://forum.nginx.org/read.php?2,178665,178665#msg-178665

Where are you setting $project?

Regards,
Richard K.

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:
http://forum.nginx.org/read.php?2,178665,178672#msg-178672

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.

On 26 Fev 2011 21h49 WET, [email protected] 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

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.
http://sysoev.ru/en/

On 26 Fev 2011 23h01 WET, [email protected] 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

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

On 27 Fev 2011 08h17 WET, [email protected] 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

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:
http://forum.nginx.org/read.php?2,178665,178688#msg-178688

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