nginx不记录任何内容


8

我正在使用nginx运行FreeBSD 9稳定服务器。
我的配置在这里:

user www www;
worker_processes 5;
error_log /var/log/nginx/nginx-error.log;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    include fastcgi_params;
    index index.html index.htm index.php;
    default_type application/octet-stream;
    log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    sendfile on;
    autoindex  on;
    tcp_nopush on;
    tcp_nodelay on;
    ignore_invalid_headers on;
    gzip on;
    server {
        listen 127.0.0.1;
        server_name localhost;
        location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
        }
    }
    server {
        listen 80;
        server_name localhost cubox.me *.cubox.me;
        access_log /var/log/nginx/nginx-access.log main;
        root /var/www;
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
#            fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
        }
    }
    server {
        listen 443;
        server_name localhost cubox.me *.cubox.me;
        access_log /var/log/nginx/nginx-access.log main;
        ssl on;
        ssl_certificate server.crt;
        ssl_certificate_key server.key;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers RC4:HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
        root /var/www;
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
        }
    }
    server {
        listen 80;
        server_name yk.cubox.me yubikey.cubox.me yubico.cubox.me;
        access_log /var/log/nginx/nginx-access.log main;
        location / {
            proxy_pass http://localhost:8000;
            proxy_set_header  X-Real-IP  $remote_addr;
        }
    }
    server {
        listen 443;
        server_name yk.cubox.me yubikey.cubox.me yubico.cubox.me;
        access_log /var/log/nginx/nginx-access.log main;
        ssl on;
        ssl_certificate server.crt;
        ssl_certificate_key server.key;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers RC4:HIGH:!aNULL:!MD5; 
        ssl_prefer_server_ciphers on;
        location / {
            proxy_pass http://localhost:8001;
            proxy_set_header  X-Real-IP  $remote_addr;
        }
    }
    server {
        listen 80;
        server_name munin.cubox.me;
        access_log /var/log/nginx/nginx-access.log main;
        root /var/www/munin;
    }
    server {
        listen 443;
        server_name munin.cubox.me;
        access_log /var/log/nginx/nginx-access.log main;
        ssl on;
        ssl_certificate server.crt;
        ssl_certificate_key server.key;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers RC4:HIGH:!aNULL:!MD5; 
        ssl_prefer_server_ciphers on;
        root /var/www/munin;
    }

}

实际上,我的问题是我没有任何日志!/var/log/nginx/nginx-access.log或-error.log为空。服务器正在运行,在配置编辑后重新启动。

drwxr-xr-x  27 root  wheel       512 31 déc 14:45 var
drwxr-xr-x   6 root        wheel    1,5k  1 jan 22:41 log
drwxr-xr-x  2 www     www       512B  1 jan 21:28 nginx
-rw-r--r--  1 www  www  0  1 jan 21:28 nginx-access.log
-rw-r--r--  1 www  www  0  2 déc 16:48 nginx-error.log

这两个文件都不是由nginx编写的,但是用户www可以访问它们。

╭─<root@Dragonborn>-</var/log/nginx>-<22:44:38>-◇
╰─➤ ps aux | grep nginx
root         29015  0,0  0,0  29140    16 ??  Is    6déc12     0:00,01 nginx: master process /usr/local/sbin/nginx
www          29016  0,0  0,2  29140  3300 ??  R     6déc12     2:56,20 nginx: worker process (nginx)
www          29017  0,0  0,1  29140  2692 ??  S     6déc12     3:04,70 nginx: worker process (nginx)
www          29018  0,0  0,2  29140  3224 ??  R     6déc12     3:06,69 nginx: worker process (nginx)
www          29019  0,0  0,1  29140  3008 ??  S     6déc12     2:54,06 nginx: worker process (nginx)
www          29020  0,0  0,1  29140  3032 ??  S     6déc12     2:53,29 nginx: worker process (nginx)

服务器没有任何其他问题,并且运行正常。

Answers:


11

我认为问题可能出在以下方面:

server {
    listen 127.0.0.1;
    server_name localhost;
    location /nginx_status {
    stub_status on;
>>>>access_log off; <<<<<<<<<<<<<<<< You are setting them to be off
    allow 127.0.0.1;
    deny all;
}

哦,我的上帝。确实,这部分代码禁用了所有日志。如何才能现在仅禁用状态日志?
Cubox

我必须说我不知道​​为什么它会阻止所有日志……如果不设置它会怎样?它不应该为“状态”服务器记录任何内容,因为没有任何默认设置,并且应该让所有其他日志继续进行。
No_or_yes 2013年

0

我有同样明显的问题,因为我试图以vim /var/log/nginx非特权用户身份登录。我需要成为超级管理员来查看日志:

sudo -s
vim /var/log/nginx/error.log
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.