这篇文章给大家分享的内容是关于常见的nginx日志以及设置方法,有一定的参考价值,有需要的朋友可以从参考一下,希望对你有所帮助。
前言
作为一名程序员,比码代码还重要那么一点点的东西就是日志的分析和查询。下面列出常见日志及设置方法。
配置文件
nginx分access_log和error_log两种日志
设置需要在nginx.conf中,默认通过源码包编译安装nginx目录应在
/usr/local/nginx
目录下,如果你通过yum或者其他方式安装,不清楚或不知道nginx具体安装目录,可以使用
立即学习“PHP免费学习笔记(深入)”;
find / -name nginx.conf
or
nginx -V | grep prefix ------------- nginx version: nginx/1.13.9 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
开启访问日志
如果是你源码包默认安装的,打开路径如下
vim /usr/local/nginx/nginx.conf
找到如下内容
酷纬企业网站管理系统Kuwebs是酷纬信息开发的为企业网站提供解决方案而开发的营销型网站系统。在线留言模块、常见问题模块、友情链接模块。前台采用DIV+CSS,遵循SEO标准。 1.支持中文、英文两种版本,后台可以在不同的环境下编辑中英文。 3.程序和界面分离,提供通用的PHP标准语法字段供前台调用,可以为不同的页面设置不同的风格。 5.支持google地图生成、自定义标题、自定义关键词、自定义描
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
...
}将log_format到access_log的注释打开即可,log_format可定义nginx的日志规格。
log_format默认规格参数表
| 名称 | 注解 |
|---|---|
| $remote_addr | 客户端/用户的IP地址 |
| $time_local | 访问时间 |
| $request | 请求方式 + 请求地址 |
| $status | 请求状态码 与HTTP状态码一致 |
| $body_bytes_sent | 请求的地址大小 以bytes格式计算 |
| $http_referer | 请求来源,从什么地方访问的 |
| $http_user_agent | 用户信息(浏览器信息) |
| $http_x_forwarded_for | 转发IP地址 |
开启错误日志
如果是你源码包默认安装的,打开路径如下
vim /usr/local/nginx/nginx.conf
找到如下内容
error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;
将注解删除即可,你可以将不同的错误类型分开存储如
error_log logs/error.log notice;
notice既为错误类型,不写则是全部。
相关文章推荐:
Nginx常用日志分割方法 nginx apache nginx php nginx rewrite
nginx常见配置










