草庐IT

nginx日志问题解决方法记录

itnihao 2023-03-28 原文
nginx版本信息如下

#nginx -V
nginx version: nginx/1.2.0  最新稳定版本
built by gcc 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/usr --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-ath=/var/log/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=www --group=www --with-http_ssl_module --with-ttp_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_stub_status_module --with-google_perftools_module --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi --http-client-body-temp-path=/var/tmp/nginx/client --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi
 nginx的配置如下

  1. user  www; 
  2. worker_processes  2; 
  3. google_perftools_profiles /var/tmp/nginx/tcmalloc/tcmalloc; 
  4. events { 
  5.     use epoll; 
  6.     worker_connections  51000; 
  7. http 
  8.     include       mime.types; 
  9.     default_type  application/octet-stream; 
  10.     keepalive_timeout     65; 
  11.     sendfile              on; 
  12.     tcp_nopush            on; 
  13.     tcp_nodelay           on; 
  14.     client_header_timeout 10; 
  15.     client_body_timeout   10; 
  16.     send_timeout          10; 
  17.     gzip  on; 
  18.     gzip_min_length       1k; 
  19.     gzip_buffers       4 16k; 
  20.     gzip_http_version    1.1; 
  21.     gzip_comp_level        2; 
  22.     gzip_types  text/plain application/x-javascript text/css applocation/xml; 
  23.     server 
  24.         listen       80; 
  25.         server_name  localhost; 
  26.         location / { 
  27.             root   html; 
  28.             index  index.html index.htm; 
  29.          } 
  30.         error_page   500 502 503 504  /50x.html; 
  31.         location = /50x.html { 
  32.             root   html; 
  33.          } 
  34.         location ~ \.php$ { 
  35.             root           html; 
  36.             fastcgi_pass   127.0.0.1:9000; 
  37.             fastcgi_index  index.php; 
  38.             fastcgi_param  SCRIPT_FILENAME  /usr/html$fastcgi_script_name; 
  39.             include        fastcgi_params; 
  40.          }   
  41.     log_format  welog  '$remote_addr - $remote_user [$time_local] "$request" ' 
  42.                '$status $body_bytes_sent "$http_referer" ' 
  43.                 '"$http_user_agent" "$http_x_forwarded_for"'; 
  44.      access_log  /var/log/nginx/access.log  weblog; 
  45.        } 
  1. 启动nginx的时候,出现警告信息
  2. #service nginx restart 
  3. nginx: [warn] the "log_format" directive may be used only on "http" level in /etc/nginx/nginx.conf:97 
  4. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
  5. nginx: configuration file /etc/nginx/nginx.conf test is successful 
  6. Stopping nginx:                                            [  OK  ] 
  7. Starting nginx: nginx: [warn] the "log_format" directive may be used only on "http" level in /etc/nginx/nginx.conf:97 
  8.                                                            [  OK  ] 
  9. 这里的警告意思是日志需要放在http内,所以做如下更改即可
 修改后的nginx.conf文件如下

  1. user  www;  
  2. worker_processes  2;  
  3. google_perftools_profiles /var/tmp/nginx/tcmalloc/tcmalloc;  
  4. events {  
  5.     use epoll;  
  6.     worker_connections  51000;  
  7.         }  
  8. http  
  9. {  
  10.     include       mime.types;  
  11.     default_type  application/octet-stream;  
  12.     keepalive_timeout     65;  
  13.     sendfile              on;  
  14.     tcp_nopush            on;  
  15.     tcp_nodelay           on;  
  16.     client_header_timeout 10;  
  17.     client_body_timeout   10;  
  18.     send_timeout          10;  
  19.     gzip  on;  
  20.     gzip_min_length       1k;  
  21.     gzip_buffers       4 16k;  
  22.     gzip_http_version    1.1;  
  23.     gzip_comp_level        2;  
  24.     gzip_types  text/plain application/x-javascript text/css applocation/xml;  
  25.     server  
  26.         listen       80;  
  27.         server_name  localhost;  
  28.         location / {  
  29.             root   html;  
  30.             index  index.html index.htm;  
  31.                     }  
  32.         error_page   500 502 503 504  /50x.html;  
  33.         location = /50x.html {  
  34.             root   html;  
  35.                               }  
  36.         location ~ \.php$ {  
  37.             root           html;  
  38.             fastcgi_pass   127.0.0.1:9000;  
  39.             fastcgi_index  index.php;  
  40.             fastcgi_param  SCRIPT_FILENAME  /usr/html$fastcgi_script_name;  
  41.             include        fastcgi_params;  
  42.                             } 
  43. }    注意,下面的日志是放在server之外的,即出现警告是放的位置不对    
  44.     log_format  welog  '$remote_addr - $remote_user [$time_local] "$request" '  
  45.                        '$status $body_bytes_sent "$http_referer" '  
  46.                        '"$http_user_agent" "$http_x_forwarded_for"';  
  47.      access_log  /var/log/nginx/access.log  weblog;  
  48.                 
  49.  }  
重启nginx服务,则OK了,

  1. service nginx restart      
  2. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
  3. nginx: configuration file /etc/nginx/nginx.conf test is successful 
  4. Stopping nginx:                                            [  OK  ] 
  5. Starting nginx:                                            [  OK  ] 
如果我需要在server里面定义日志,该怎么实现呢,如下

  1. user  www;   
  2. worker_processes  2;   
  3. google_perftools_profiles /var/tmp/nginx/tcmalloc/tcmalloc;   
  4. events {   
  5.     use epoll;   
  6.     worker_connections  51000;   
  7.         }   
  8. http   
  9.   
  10.     include       mime.types;   
  11.     default_type  application/octet-stream;   
  12.     keepalive_timeout     65;   
  13.     sendfile              on;   
  14.     tcp_nopush            on;   
  15.     tcp_nodelay           on;   
  16.     client_header_timeout 10;   
  17.     client_body_timeout   10;   
  18.     send_timeout          10;   
  19.     gzip  on;   
  20.     gzip_min_length       1k;   
  21.     gzip_buffers       4 16k;   
  22.     gzip_http_version    1.1;   
  23.     gzip_comp_level        2;   
  24.     gzip_types  text/plain application/x-javascript text/css applocation/xml;   
  25.     server   
  26.         listen       80;   
  27.         server_name  localhost;   
  28.         location / {   
  29.             root   html;   
  30.             index  index.html index.htm;   
  31.                     }   
  32.         error_page   500 502 503 504  /50x.html;   
  33.         location = /50x.html {   
  34.             root   html;   
  35.                               }   
  36.         location ~ \.php$ {   
  37.             root           html;   
  38.             fastcgi_pass   127.0.0.1:9000;   
  39.             fastcgi_index  index.php;   
  40.             fastcgi_param  SCRIPT_FILENAME  /usr/html$fastcgi_script_name;   
  41.             include        fastcgi_params;
  42.  }   
  43.             access_log /var/log/nginx/access2.log;  此处定义的日志格式,不需要在后面加日志格式    
  44.     注意,下面的日志是放在server之外的,即出现警告是放的位置不对     
  45.      log_format  welog  '$remote_addr - $remote_user [$time_local] "$request" '   
  46.                         '$status $body_bytes_sent "$http_referer" '   
  47.                         '"$http_user_agent" "$http_x_forwarded_for"';   
  48.      access_log  /var/log/nginx/access.log  weblog;   
  49.                  
  50.  }  
更多nginx日志问题,参考nginx的wiki: http://wiki.nginx.org/HttpLogModule
最终于解决问题的是这个url            http://thread.gmane.org/gmane.comp.web.nginx.english/9277
                                     itnihao 2012年5月3号于成都
转载请注明以上信息

有关nginx日志问题解决方法记录的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  5. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

  6. Ruby 方法() 方法 - 2

    我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby​​-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco

  7. ruby - 通过 rvm 升级 ruby​​gems 的问题 - 2

    尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub

  8. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  9. ruby - Highline 询问方法不会使用同一行 - 2

    设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案

  10. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

随机推荐