Dynamic logs

Hi,
I’m using version 0.716 and trying to make dynamic log files work.
The log file is created but subsequently nothing is written inside the
file.
The configuration is as follows:

Catch all web site

server {
server_name _ ;

    location  /widgets/ { alias  /home/http/lib/widgets/; }
    rewrite ^/crm/(.*)$ https://$host/crm/$1 permanent;

    if ($host ~* 

“^([^.]+(.[^.]+)).((.).(com|net|org)(…*)?)$”){
set $subd $1;
set $dom $3;
set $myroot /sites/$dom/$subd/htdocs ;
}

    location / {
       index  index.php index.html index.htm;
    }

    root            /home/http$myroot ;
    include         php-fastcgi;

    access_log  /var/log/nginx/$dom debug ;

}

I get an error as follows:
2008/09/12 02:06:19 [alert] 9832#0: *6 write() to
“/var/log/nginx/be-o.com”
failed (22: Invalid argument) while logging request,

Can anyone help

Thank you

Vladan

On Thu, Sep 11, 2008 at 08:15:30PM +0000, Vladan Popovic wrote:

    rewrite ^/crm/(.*)$ https://$host/crm/$1 permanent;

failed (22: Invalid argument) while logging request,
Could you run nginx using truss/ktrace/strace and try the request ?

Igor S. <is@…> writes:

    server_name _ ;
    location / {

I get an error as follows:
2008/09/12 02:06:19 [alert] 9832#0: *6 write() to “/var/log/nginx/be-o.com”
failed (22: Invalid argument) while logging request,

Could you run nginx using truss/ktrace/strace and try the request ?
Hello Igor,
I am sorry but I don’t know these tools - i never used them and don’t
really
know what I should do with them.
I am using Ubuntu 8.04 and strace is present so I ran it but it
generated a log
of text on the screen that I didn’t understand.
The user that is the owner of the log file is www-data and I did ‘su
www-data’
and then I could write in the log file manually so the problem doesn’t
seem
related to user rights.

Best Regards

Vladan

Dear Igor,

Sorry for not being more knowledgeable …
I have init.d/nginx script to manage nginx.
Should i run strace /etc/init.d/nginx restart or should i run another
instruction?
(i did ‘strace /etc/init.d/nginx’ but couldn’t find the string you are
looking for)

Best Regards

Vladan

On Thu, Sep 11, 2008 at 10:51:34PM +0000, Vladan Popovic wrote:

    }

}
I am using Ubuntu 8.04 and strace is present so I ran it but it generated a log
of text on the screen that I didn’t understand.
The user that is the owner of the log file is www-data and I did ‘su www-data’
and then I could write in the log file manually so the problem doesn’t seem
related to user rights.

You need to find something like ‘open “/var/log/nginx/be-o.com”’ in
strace output and send the line and about 10 lines after it to me.

Igor S. <is@…> writes:

Try the following:
3) then run nginx directly under strace:

strace /usr/sbin/nginx

  1. and make request.

OK - i think i managed to do it … here’s the extract:

open("/var/log/nginx/be-o.com", O_RDWR|O_CREAT|O_APPEND, 0644) = 14
fstat(14, {st_mode=S_IFREG|0644, st_size=0, …}) = 0
fcntl(14, F_GETFL) = 0x8402 (flags
O_RDWR|O_APPEND|O_LARGEFILE)
fcntl(14, F_SETFL, O_RDWR|O_APPEND|O_DIRECT|O_LARGEFILE) = 0
write(14, “192.168.1.16 - - [12/Sep/2008:19”…, 196) = -1 EINVAL
(Invalid
argument)
close(14) = 0
close(13) = 0
setsockopt(12, SOL_TCP, TCP_NODELAY, [1], 4) = 0
recvfrom(12, 0x6a3620, 1024, 0, 0, 0) = -1 EAGAIN (Resource
temporarily
unavailable)
epoll_wait(7, {{EPOLLIN, {u32=7148785, u64=7148785}}}, 512, 28931) = 1
recvfrom(9, “GET /img/bottom_right.gif HTTP/1”…, 1024, 0, NULL, NULL)
= 457
open("/home/http/sites/be-o.com/www/htdocs/img/bottom_right.gif",
O_RDONLY) = 13
fstat(13, {st_mode=S_IFREG|0644, st_size=168, …}) = 0
writev(9, [{“HTTP/1.1 304 Not Modified\r\nServe”…, 158}], 1) = 158
open("/var/log/nginx/be-o.com", O_RDWR|O_CREAT|O_APPEND, 0644) = 14
fstat(14, {st_mode=S_IFREG|0644, st_size=0, …}) = 0
fcntl(14, F_GETFL) = 0x8402 (flags
O_RDWR|O_APPEND|O_LARGEFILE)
fcntl(14, F_SETFL, O_RDWR|O_APPEND|O_DIRECT|O_LARGEFILE) = 0
write(14, “192.168.1.16 - - [12/Sep/2008:19”…, 205) = -1 EINVAL
(Invalid
argument)
close(14) = 0
close(13) = 0
recvfrom(9, 0x6a2ee0, 1024, 0, 0, 0) = -1 EAGAIN (Resource
temporarily
unavailable)
epoll_wait(7, {{EPOLLIN|EPOLLOUT, {u32=7148624, u64=7148624}}}, 512,
28561) = 1
recvfrom(8, “GET /default.css HTTP/1.1\r\nHost:”…, 1024, 0, NULL,
NULL) = 433
open("/home/http/sites/be-o.com/www/htdocs/default.css", O_RDONLY) = 13
fstat(13, {st_mode=S_IFREG|0644, st_size=1881, …}) = 0
writev(8, [{“HTTP/1.1 304 Not Modified\r\nServe”…, 158}], 1) = 158
open("/var/log/nginx/be-o.com", O_RDWR|O_CREAT|O_APPEND, 0644) = 14
fstat(14, {st_mode=S_IFREG|0644, st_size=0, …}) = 0
fcntl(14, F_GETFL) = 0x8402 (flags
O_RDWR|O_APPEND|O_LARGEFILE)

On Fri, Sep 12, 2008 at 07:38:42AM +0000, Vladan Popovic wrote:

Sorry for not being more knowledgeable …
I have init.d/nginx script to manage nginx.
Should i run strace /etc/init.d/nginx restart or should i run another
instruction?
(i did ‘strace /etc/init.d/nginx’ but couldn’t find the string you are
looking for)

Try the following:

  1. stop nginx via “/etc/init.d/nginx stop”

  2. add temporarily in nginx.conf:

daemon off;
master_process off;

This will force nginx to run single process only.

  1. then run nginx directly under strace:

strace /usr/sbin/nginx

  1. and make request.

Hello!

On Fri, Sep 12, 2008 at 03:41:03PM +0400, Maxim D. wrote:

another > instruction?
master_process off;

open("/var/log/nginx/be-o.com", O_RDWR|O_CREAT|O_APPEND, 0644) = 14
fstat(14, {st_mode=S_IFREG|0644, st_size=0, …}) = 0
fcntl(14, F_GETFL) = 0x8402 (flags
O_RDWR|O_APPEND|O_LARGEFILE)
fcntl(14, F_SETFL, O_RDWR|O_APPEND|O_DIRECT|O_LARGEFILE) = 0
write(14, “192.168.1.16 - - [12/Sep/2008:19”…, 196) = -1 EINVAL
(Invalid argument)

Could you please check if ‘directio off;’ helps? It should.

I was wrong, it shouldn’t help. Try the patch instead.

Maxim D.

Hello!

On Fri, Sep 12, 2008 at 11:10:02AM +0000, Vladan Popovic wrote:

looking for)
This will force nginx to run single process only.
fstat(14, {st_mode=S_IFREG|0644, st_size=0, …}) = 0
fcntl(14, F_GETFL) = 0x8402 (flags
O_RDWR|O_APPEND|O_LARGEFILE)
fcntl(14, F_SETFL, O_RDWR|O_APPEND|O_DIRECT|O_LARGEFILE) = 0
write(14, “192.168.1.16 - - [12/Sep/2008:19”…, 196) = -1 EINVAL (Invalid
argument)

Could you please check if ‘directio off;’ helps? It should.

Also the following patch should help without switching off
directio:

— a/src/core/ngx_open_file_cache.c
+++ b/src/core/ngx_open_file_cache.c
@@ -498,7 +498,7 @@ ngx_open_and_stat_file(u_char *name, ngx
} else {
of->fd = fd;

  •    if (of->directio <= ngx_file_size(&fi)) {
    
  •    if (!of->log && of->directio <= ngx_file_size(&fi)) {
            if (ngx_directio(fd) == -1) {
                ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
                              ngx_directio_n " \"%s\" failed", name);
    

Maxim D.

Thank you Igor, I applied the patch and it’s working now.
Do you have an oppinion on whether such log files impact performance
significantly?

On Fri, Sep 12, 2008 at 04:20:02PM +0400, Maxim D. wrote:

(Invalid argument)

Could you please check if ‘directio off;’ helps? It should.

I was wrong, it shouldn’t help. Try the patch instead.

Yes, the patch will help only. However, I prefer different one.

On Fri, Sep 12, 2008 at 01:06:30PM +0000, Vladan Popovic wrote:

Thank you Igor, I applied the patch and it’s working now.
Do you have an oppinion on whether such log files impact performance
significantly?

I believe it should not impact significantly. However, I never use such
log files.

On Thu, Sep 11, 2008 at 08:15:30PM +0000, Vladan Popovic wrote:

    rewrite ^/crm/(.*)$ https://$host/crm/$1 permanent;

    root            /home/http$myroot ;
    include         php-fastcgi;

    access_log  /var/log/nginx/$dom debug ;

}

BTW, it’s better to use

server {
server_name _ ;

    root        /home/http$myroot ;
    access_log  /var/log/nginx/$dom debug ;

    if ($host ~* 

“^([^.]+(.[^.]+)).((.).(com|net|org)(…*)?)$”){
set $dom $3;
set $myroot /sites/$dom/$1/htdocs ;
}

    location / {
       index  index.php index.html index.htm;
    }

    include         php-fastcgi;

    location ^~ /widgets/ { alias  /home/http/lib/widgets/; }

    location ^~ /crm/ { rewrite  ^  https://$host/$request_uri 

permanent; }
}

What is in php-fastcgi ?

Igor S. <is@…> writes:

            set $myroot /sites/$dom/$1/htdocs ;
    location ^~ /crm/ { rewrite  ^  https://$host/$request_uri permanent; }

}

What is in php-fastcgi ?

thank you, but why is the order important?
php-fastcgi contains the following:

pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param HTTPS $ssl;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME

/home/http$myroot$fastcgi_script_name;
include fastcgi_params;
}