【问题标题】:Where can I find the error logs of nginx, using FastCGI and Django?我在哪里可以找到使用 FastCGI 和 Django 的 nginx 的错误日志?
【发布时间】:2010-12-14 22:26:14
【问题描述】:

我正在使用带有FastCGI + nginx 的 Django。这种情况下的日志(错误)存储在哪里?

【问题讨论】:

    标签: django nginx fastcgi error-log


    【解决方案1】:

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

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

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

    /usr/local/var/log/nginx
    

    【讨论】:

    • 这可能取决于版本,但我的日志在里面:/opt/nginx/logs/error.log
    • 在 Mac OS X 上使用自制软件:/usr/local/var/log/nginx。见 lfender 的answer
    • 在 ubuntu 上,我在 /var/log/nginx/error.log 中有它。最好检查nginx.conf文件,找到error_log设置。
    【解决方案2】:

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

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

    /var/log/nginx/error.log
    

    【讨论】:

    【解决方案3】:

    我的 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/ 是您希望开始搜索的文件夹。

    【讨论】:

    • 如果你用 Homebrew 安装了 Nginx,日志会在这里。
    【解决方案4】:

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

    示例:

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

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

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

    $ 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 发出相同的命令。

    您可以阅读更多here

    【讨论】:

    • 这是一个好记的技巧.. 不用再猜测日志文件的位置了
    • 这教会了我如何钓鱼;希望我能投票更多
    • +1 有关如何查看的答案。我正在寻找来自不同 nginx 安装的日志,但它不在最佳答案中。
    • 您可以在/proc 文件系统中查看Linux 上的类似数据。 /proc/${pid}/fd 具有指向打开的文件、管道、设备等的符号链接
    【解决方案5】:
    cd /var/log/nginx/
    cat error.log
    

    【讨论】:

      【解决方案6】:

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

      tail -f /var/log/nginx/error.log
      

      【讨论】:

        【解决方案7】:

        在终端输入这个命令:

        sudo cat /var/log/nginx/error.log
        

        【讨论】:

        • 这不是答案,应该是评论。一旦您有足够的声誉,您就可以发表评论。
        【解决方案8】:

        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
        

        【讨论】:

          【解决方案9】:

          我在/usr/local/nginx/logs/*找到它。

          【讨论】:

          • 请考虑解释您的代码以及它将如何提供帮助,以便其他人可以从中受益。
          【解决方案10】:

          最好在 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;
          # ...
          }
          

          【讨论】:

            【解决方案11】:

            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
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2010-10-03
              • 2013-11-11
              • 2014-09-13
              • 2012-10-01
              • 2021-12-06
              • 2022-01-23
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多