这篇文章给大家分享的内容是关于常见的nginx日志以及设置方法,有一定的参考价值,有需要的朋友可以从参考一下,希望对你有所帮助。
前言作为一名程序员,比码代码还重要那么一点点的东西就是日志的分析和查询。下面列出常见日志及设置方法。
配置文件nginx分access_log和error_log两种日志
设置需要在nginx.conf中,默认通过源码包编译安装nginx目录应在
/usr/local/nginx
目录下,如果你通过yum或者其他方式安装,不清楚或不知道nginx具体安装目录,可以使用
find / -name nginx.conf
or
nginx -v | grep prefix-------------nginx version: nginx/1.13.9built by gcc 4.8.5 20150623 (red hat 4.8.5-16) (gcc)built with openssl 1.0.2k-fips 26 jan 2017tls sni support enabledconfigure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
开启访问日志如果是你源码包默认安装的,打开路径如下
vim /usr/local/nginx/nginx.conf
找到如下内容
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常见配置
以上就是php中常见的nginx日志以及配置的方法的详细内容。