nginx日志问题解决方法记录
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的配置如下
[*]userwww;
[*]worker_processes2;
[*]google_perftools_profiles /var/tmp/nginx/tcmalloc/tcmalloc;
[*]events {
[*] use epoll;
[*] worker_connections51000;
[*] }
[*]http
[*]{
[*] include mime.types;
[*] default_typeapplication/octet-stream;
[*] keepalive_timeout 65;
[*] sendfile on;
[*] tcp_nopush on;
[*] tcp_nodelay on;
[*] client_header_timeout 10;
[*] client_body_timeout 10;
[*] send_timeout 10;
[*] gzipon;
[*] gzip_min_length 1k;
[*] gzip_buffers 4 16k;
[*] gzip_http_version 1.1;
[*] gzip_comp_level 2;
[*] gzip_typestext/plain application/x-javascript text/css applocation/xml;
[*] server {
[*] listen 80;
[*] server_namelocalhost;
[*] location / {
[*] root html;
[*] indexindex.html index.htm;
[*] }
[*] error_page 500 502 503 504/50x.html;
[*] location = /50x.html {
[*] root html;
[*] }
[*] location ~ \.php$ {
[*] root html;
[*] fastcgi_pass 127.0.0.1:9000;
[*] fastcgi_indexindex.php;
[*] fastcgi_paramSCRIPT_FILENAME/usr/html$fastcgi_script_name;
[*] include fastcgi_params;
[*] }
[*] log_formatwelog'$remote_addr - $remote_user [$time_local] "$request" '
[*] '$status $body_bytes_sent "$http_referer" '
[*] '"$http_user_agent" "$http_x_forwarded_for"';
[*] access_log/var/log/nginx/access.logweblog;
[*] }
[*] }
[*]启动nginx的时候,出现警告信息
[*]#service nginx restart
[*]nginx: the "log_format" directive may be used only on "http" level in /etc/nginx/nginx.conf:97
[*]nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
[*]nginx: configuration file /etc/nginx/nginx.conf test is successful
[*]Stopping nginx:
[*]Starting nginx: nginx: the "log_format" directive may be used only on "http" level in /etc/nginx/nginx.conf:97
[*]
[*]这里的警告意思是日志需要放在http内,所以做如下更改即可
修改后的nginx.conf文件如下
[*]userwww;
[*]worker_processes2;
[*]google_perftools_profiles /var/tmp/nginx/tcmalloc/tcmalloc;
[*]events {
[*] use epoll;
[*] worker_connections51000;
[*] }
[*]http
[*]{
[*] include mime.types;
[*] default_typeapplication/octet-stream;
[*] keepalive_timeout 65;
[*] sendfile on;
[*] tcp_nopush on;
[*] tcp_nodelay on;
[*] client_header_timeout 10;
[*] client_body_timeout 10;
[*] send_timeout 10;
[*] gzipon;
[*] gzip_min_length 1k;
[*] gzip_buffers 4 16k;
[*] gzip_http_version 1.1;
[*] gzip_comp_level 2;
[*] gzip_typestext/plain application/x-javascript text/css applocation/xml;
[*] server {
[*] listen 80;
[*] server_namelocalhost;
[*] location / {
[*] root html;
[*] indexindex.html index.htm;
[*] }
[*] error_page 500 502 503 504/50x.html;
[*] location = /50x.html {
[*] root html;
[*] }
[*] location ~ \.php$ {
[*] root html;
[*] fastcgi_pass 127.0.0.1:9000;
[*] fastcgi_indexindex.php;
[*] fastcgi_paramSCRIPT_FILENAME/usr/html$fastcgi_script_name;
[*] include fastcgi_params;
[*] }
[*] } 注意,下面的日志是放在server之外的,即出现警告是放的位置不对
[*] log_formatwelog'$remote_addr - $remote_user [$time_local] "$request" '
[*] '$status $body_bytes_sent "$http_referer" '
[*] '"$http_user_agent" "$http_x_forwarded_for"';
[*] access_log/var/log/nginx/access.logweblog;
[*]
[*] }
重启nginx服务,则OK了,
[*]service nginx restart
[*]nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
[*]nginx: configuration file /etc/nginx/nginx.conf test is successful
[*]Stopping nginx:
[*]Starting nginx:
如果我需要在server里面定义日志,该怎么实现呢,如下
[*]userwww;
[*]worker_processes2;
[*]google_perftools_profiles /var/tmp/nginx/tcmalloc/tcmalloc;
[*]events {
[*] use epoll;
[*] worker_connections51000;
[*] }
[*]http
[*]{
[*] include mime.types;
[*] default_typeapplication/octet-stream;
[*] keepalive_timeout 65;
[*] sendfile on;
[*] tcp_nopush on;
[*] tcp_nodelay on;
[*] client_header_timeout 10;
[*] client_body_timeout 10;
[*] send_timeout 10;
[*] gzipon;
[*] gzip_min_length 1k;
[*] gzip_buffers 4 16k;
[*] gzip_http_version 1.1;
[*] gzip_comp_level 2;
[*] gzip_typestext/plain application/x-javascript text/css applocation/xml;
[*] server {
[*] listen 80;
[*] server_namelocalhost;
[*] location / {
[*] root html;
[*] indexindex.html index.htm;
[*] }
[*] error_page 500 502 503 504/50x.html;
[*] location = /50x.html {
[*] root html;
[*] }
[*] location ~ \.php$ {
[*] root html;
[*] fastcgi_pass 127.0.0.1:9000;
[*] fastcgi_indexindex.php;
[*] fastcgi_paramSCRIPT_FILENAME/usr/html$fastcgi_script_name;
[*] include fastcgi_params;
[*] }
[*] access_log/var/log/nginx/access2.log;此处定义的日志格式,不需要在后面加日志格式
[*] } 注意,下面的日志是放在server之外的,即出现警告是放的位置不对
[*] log_formatwelog'$remote_addr - $remote_user [$time_local] "$request" '
[*] '$status $body_bytes_sent "$http_referer" '
[*] '"$http_user_agent" "$http_x_forwarded_for"';
[*] access_log/var/log/nginx/access.logweblog;
[*]
[*] }
更多nginx日志问题,参考nginx的wiki: http://wiki.nginx.org/HttpLogModule
最终于解决问题的是这个url http://thread.gmane.org/gmane.comp.web.nginx.english/9277
itnihao 2012年5月3号于成都
转载请注明以上信息
页:
[1]