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. }
  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. log_format  welog  '$remote_addr - $remote_user [$time_local] "$request" '
  44. '$status $body_bytes_sent "$http_referer" '
  45. '"$http_user_agent" "$http_x_forwarded_for"';
  46. access_log  /var/log/nginx/access.log  weblog;
  47. }
  48. }
  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. }

重启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. }
更多nginx日志问题,参考nginx的wiki: http://wiki.nginx.org/HttpLogModule
最终于解决问题的是这个url            http://thread.gmane.org/gmane.comp.web.nginx.english/9277
itnihao 2012年5月3号于成都
转载请注明以上信息

转载于:https://blog.51cto.com/itnihao/851716

nginx日志问题解决方法记录相关推荐

  1. cannot create file怎么解决_内核问题解决方法记录

    内核问题解决方法记录 ♪ 张释文 在内核开发这块,基本工作都是:打补丁,调补丁,调bug.最耗神的就是调bug,调bug的过程最花时间的一步是定位问题,基本上只要定位到问题,解决起来就容易些了(目前我 ...

  2. VS2008运行过程中出现regsvr32问题解决方法记录

    VS2008运行过程中出现regsvr32问题解决方法 vs2008运行工程文件过程中提示regsvr32出现问题,此时我的项目中有3个工程,两个是依赖,第三个是我建立的运行工程,出现这个问题之后,我 ...

  3. centos yum安装nginx 提示 No package nginx available问题解决方法

    问题原因: nginx位于第三方的yum源里面,而不在centos官方yum源里面 解决方法: 安装epel(Extra Packages for Enterprise Linux) a.去epel网 ...

  4. android应用开发中收集的异常日志解决方法记录

    这里主要是列出开发中收集的一些错误日志,以及解决方案,仅供参考,也有待解决的问题 1, ListView 中出现java.lang.IndexOutOfBoundsException: Invalid ...

  5. Idea中Maven控制的多模块项目运行不到最新的代码,写的代码不生效问题解决方法记录。

    文章目录 写在前边 我的情况 解决办法 原因分析 写在前边 这个方法不一定适合所有情况,兄弟遇到这种情况首先需要保持冷静.可以先参考我们的情况是否一致,再决定是否看下去. 我的情况 idea版本:20 ...

  6. Ubuntu上Github下载慢的问题解决方法记录

    1.程序员们经常使用git clone +网址下载github上的代码,但是只有几k的速度,然后经常中途下载失败.现记录一下自己的解决办法.git clone特别慢是因为github.global.s ...

  7. Ubuntu18上Github下载慢的问题解决方法记录

    1.程序员们经常使用git clone +网址下载github上的代码,但是只有几k的速度,然后经常中途下载失败.现记录一下自己的解决办法.git clone特别慢是因为github.global.s ...

  8. 关于keil常见问题解决方法记录error: #268: declaration may not appear after executable statement in block

    error: #268: declaration may not appear after executable statement in block 因为keil 默认编译标准是C89,解决方法:

  9. 关于pycharm+opencv没有代码提示的问题解决方法记录

    代码可以看出实际我们引入的应该是cv2.cv2下面. 所以我们代码只需要import cv2.cv2 as cv 即可. 记着要重新启动下pycharm哦. 可以参考: https://blog.cs ...

最新文章

  1. 精华阅读第 10 期 |解开阿尔法狗(AlphaGo)人工智能的画皮
  2. 常见文件、目录、路径操作函数
  3. 【2012百度之星/资格赛】C: 易手机的套餐
  4. caffe训练输入数据格式介绍(LMDB/imagelist)
  5. 128位java_求一个java算法,用128位密钥的AES加密128位明文,得出的密文还是128位...很着急,非常感谢各位大神,求救!...
  6. 【.NET Core 3.0】 46 ║ 授权认证:自定义返回格式
  7. Git操作常用的命令都在这里了
  8. PCL学习(三) SAC-IA 估记object pose
  9. 大数据_Flink_Java版_状态管理(2)_算子状态---Flink工作笔记0061
  10. 第45届国际大学生程序设计竞赛(ICPC)沈阳站太原理工大学收获1枚铜牌
  11. 100 个 pandas 案例,强烈建议保存
  12. 牛逼!一款基于SpringBoot的微信点餐系统
  13. 怎么制作html静态页面,如何做静态网页
  14. 南京邮电大学离散数学实验一(求主析取和主合取范式)
  15. 固定资产管理系统项目总结
  16. STM32开源代码——TM1637四位数码管
  17. PS4 自建HEN服务器 | 使用IDM 克隆整个网站
  18. 企业上云成趋势 看超融合如何开箱即用、一步上云
  19. PCL5打印机命令语言功能参考
  20. 08-微服务版单点登陆系统(SSO)实践

热门文章

  1. SAP WM 有无保存WM Level历史库存的Table?
  2. torch_{geometric/scatter}中一些函数的用法(softmax,scatter)
  3. 人为什么要睡觉?科学家给出进一步答案
  4. 认知科学顶刊:挑战过去50年神经科学观点,人类智力的优势或来自于记忆储存方式...
  5. Python 什么时候会被取代?
  6. Gartner 2019 年 BI 炒作周期五大趋势:增强分析、数字文化、关系分析、决策智能、实施和扩展...
  7. 最先进的AI还不如动物聪明?首届AI-动物奥运会英国开赛!
  8. 科学:揭示自由意志的生物学本质
  9. 脑机交互研究及标准化实践
  10. “强化学习之父”萨顿:预测学习马上要火,AI将帮我们理解人类意识