419

我将 Django 与FastCGI + nginx 一起使用。在这种情况下,日志(错误)存储在哪里?

4

11 回答 11

550

错误存储在 nginx 日志文件中。您可以在 nginx 配置文件的根目录中指定它:

error_log  /var/log/nginx/nginx_error.log  warn;

在带有Homebrew的Mac OS X 上,日志文件默认位于以下位置:

/usr/local/var/log/nginx
于 2009-11-10T11:30:08.073 回答
326

我一直在寻找不同的解决方案。

默认情况下,在我的系统(x86 Arch Linux)上设置任何配置之前,错误日志位于:

/var/log/nginx/error.log
于 2013-09-01T09:10:52.040 回答
186

在大多数情况下,您可以在不知道配置的情况下使用lsof(list of open files) 来查找打开的日志文件。

例子:

查找 PID httpd(同样的概念适用于 nginx 和其他程序):

$ ps aux | grep httpd
...
root     17970  0.0  0.3 495964 64388 ?        Ssl  Oct29   3:45 /usr/sbin/httpd
...

lsof然后使用PID搜索打开的日志文件:

$ 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.

您可以在这里阅读更多内容。

于 2014-12-10T16:06:46.330 回答
106

运行此命令,检查错误日志:

tail -f /var/log/nginx/error.log
于 2015-10-05T15:37:52.737 回答
42

我的 ngninx 日志位于此处:

/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;

Nginx 通常设置在/usr/local/etc/. 服务器也可以配置为转储日志/var/log

如果您有 nginx 安装的备用位置并且所有其他操作都失败了,则可以使用该find命令找到您选择的文件。

find /usr/ -path "*/nginx/*" -type f -name '*.log'/usr/您希望开始搜索的文件夹在哪里。

于 2014-12-10T13:44:46.150 回答
18

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
于 2018-09-06T12:34:24.283 回答
6

在终端中输入以下命令:

sudo cat /var/log/nginx/error.log
于 2018-01-04T06:05:15.957 回答
4
cd /var/log/nginx/
cat error.log
于 2015-06-09T06:12:29.630 回答
2

对于Mac OS用户,您可以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
于 2021-06-26T03:48:10.380 回答
0

最好在 nginx 配置文件中设置访问日志的位置。使用 accesss_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;
# ...
}
于 2021-01-06T11:48:47.537 回答
-1

我在/usr/local/nginx/logs/*.

于 2019-07-16T11:36:02.247 回答