我正在使用Django与FastCGI + nginx。在这种情况下,日志(错误)存储在哪里?
error_log /var/log/nginx/nginx_error.log warn;
在Mac OS X上使用Homebrew,默认情况下日志文件位于以下位置:
/usr/local/var/log/nginx
--error-log-path
来进行配置,该选项需要在编译时设置。详情请参考http://trac.nginx.org/nginx/ticket/147。 - Michael Berkowski在大多数情况下,您可以使用lsof
(打开文件列表)来查找打开的日志文件,而无需了解配置。
示例:
查找 httpd
的 PID(相同的概念适用于nginx和其他程序):
$ ps aux | grep httpd
...
root 17970 0.0 0.3 495964 64388 ? Ssl Oct29 3:45 /usr/sbin/httpd
...
然后使用 lsof
命令并带上进程ID来搜索开放的日志文件:
$ lsof -p 17970 | grep log
httpd 17970 root 2w REG 253,15 2278 6723 /var/log/httpd/error_log
httpd 17970 root 12w REG 253,15 0 1387 /var/log/httpd/access_log
如果您期望能够找到日志文件但lsof
没有输出任何内容,请使用sudo
再次尝试相同的命令。更多信息请参见这里。/proc
文件系统中查看类似的数据。/proc/${pid}/fd
有指向打开的文件、管道、设备等的符号链接。 - Avindra Goolcharan运行此命令,以检查错误日志:
tail -f /var/log/nginx/error.log
我的nginx日志存放在这里:
/usr/local/var/log/nginx/*
您还可以检查您的nginx.conf
文件,看看是否有指令转储到自定义日志中。
运行nginx -t
命令来定位您的nginx.conf
文件。
# in ngingx.conf
error_log /usr/local/var/log/nginx/error.log;
error_log /usr/local/var/log/nginx/error.log notice;
error_log /usr/local/var/log/nginx/error.log info;
/usr/local
或/etc/
中。服务器也可以配置为将日志转储到/var/log
中。find
命令来查找所需文件。
find /usr/ -path "*/nginx/*" -type f -name '*.log'
,其中/usr/
是您希望开始搜索的文件夹。Linux服务器上的日志位置:
Apache – /var/log/httpd/
IIS – C:\inetpub\wwwroot\
Node.js – /var/log/nodejs/
nginx – /var/log/nginx/
Passenger – /var/app/support/logs/
Puma – /var/log/puma/
Python – /opt/python/log/
Tomcat – /var/log/tomcat8
sudo cat /var/log/nginx/error.log
nginx -help
。nginx version: nginx/1.21.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /opt/homebrew/Cellar/nginx/1.21.0/)
-e filename : set error log file (default: /opt/homebrew/var/log/nginx/error.log)
-c filename : set configuration file (default: /opt/homebrew/etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
然后,您可以找到一些默认路径用于配置和日志文件,在这种情况下:
/opt/homebrew/log/nginx/error.log
cd /var/log/nginx/
cat error.log
在nginx配置文件中设置访问日志的位置是一个好习惯。使用access_log /path/,像这样。
keyval $remote_addr:$http_user_agent $seen zone=clients;
server { listen 443 ssl;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
if ($seen = "") {
set $seen 1;
set $logme 1;
}
access_log /tmp/sslparams.log sslparams if=$logme;
error_log /pathtolog/error.log;
# ...
}
/opt/nginx/logs/error.log
中。 - jmarceli/var/log/nginx/error.log
中。最好检查nginx.conf
文件并找到error_log
设置。 - MarthyMnginx -h
命令来查看默认的日志输出目录。 - takanuva15