0
点赞
收藏
分享

微信扫一扫

nginx05 日志管理


nginx05 日志管理

1. nginx.conf文件样例

2;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


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" '
'$connection $upstream_addr '
'$upstream_response_time $request_time';

log_format yq '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$connection $upstream_addr '
'$upstream_response_time $request_time '
'$http_cookie';

access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 30;\
server_tokens off;

gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_types text/plain application/x-javascript text/css application/xml;

ssi on;
ssi_silent_errors on;
ssi_types text/shtml;

client_header_buffer_size 4k;

upstream eservice {
server 10.32.48.31:7015;
}

upstream taobao {
server 10.32.48.100:7001 max_fails=0;
server 10.32.48.106:7001 max_fails=0;
server 10.32.48.107:7001 max_fails=0;
}

upstream thirdIF {
server 10.32.48.79:7001 max_fails=0;
server 10.32.48.80:7001 max_fails=0;
}

upstream third {
server 10.56.81.179:7004 max_fails=0;
#server 10.32.48.80:7001 max_fails=0;
}

upstream mtp {
server 10.56.81.180:7001;
}
server {
listen 7009;
server_name gh_open;
include proxy.conf;

#ssl on;
#ssl_certificate /weblogic/nginx/key/server.pem;
#ssl_certificate_key /weblogic/nginx/key/server.key;
#ssl_session_timeout 5m;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#ssl_prefer_server_ciphers on;

location / {
proxy_pass http://10.56.81.137:7001;
}


location /coop/xinlian/ {
proxy_pass http://www.baidu.com;
}

#过滤地址
location /uddiexplorer/ {
return 404;
}

location /console {
return 404;
}
}
server {
listen 8008;
server_name eservice_stg;
include proxy.conf;

location / {
proxy_pass http://10.56.80.129:7001;
}
location ^~ /ebiz/third/noahwm.action {
rewrite ^/ebiz/third/noahwm.action?$ /third/entry.do?partner=noahwm& last;
}
#过滤地址
location /uddiexplorer/ {
return 404;
}

location /console {
return 404;
}
}
}

2.nginx日志管理的意义

1.通过访问日志,你可以得到用户地域来源、跳转来源、使用终端、某个URL访问量等相关信息;
2.通过错误日志,你可以得到系统某个服务或server的性能瓶颈等。因此,将日志好好利用,你可以得到很多有价值的信息。

3.nginx日志管理的指令

access_log
log_format

3.1.access_log

语法:

access_log path [format [buffer=size | off ] 
默认值: access_log log/access.log combined

作用域:

http, server, location

备注
(引述 ​​​http://www.nginx.cn/doc/standard/httplog.html​​)

1.指令 access_log 指派路径、格式和缓存大小。
2.参数 "off" 将清除当前级别的所有 access_log 指令。
3.如果未指定格式,则使用预置的 "combined" 格式。
4.缓存不能大于能写入磁盘的文件的最大大小。
5. FreeBSD 3.0-6.0

3.2.log_format

语法:

log_format name format [format ...]
默认值: log_format combined "..."

作用域:

http server

4.nginx日志管理的格式

$remote_addr

客户端的ip地址(代理服务器,显示代理服务ip)

$remote_user

用于记录远程客户端的用户名称(一般为“-”)

$time_local

用于记录访问时间和时区

$request

用于记录请求的url以及请求方法

$status

响应状态码,例如:200成功、404页面找不到等。

$body_bytes_sent

给客户端发送的文件主体内容字节数

$http_user_agent

用户所使用的代理(一般为浏览器)

$http_x_forwarded_for

可以记录客户端IP,通过代理服务器来记录客户端的ip地址

$http_referer

可以记录用户是从哪个链接访问过来的

备注:

Directive log_format describes the format of a log entry. Besides general variables in the format it is possible to use variables which exist only at the moment of record into the log:

$body_bytes_sent, the number of bytes, transmitted to client minus the response headers, variable is compatible with parameter %B of module Apache's mod_log_config (this was called $apache_bytes_sent, before version 0.3.10)
$bytes_sent, the number of bytes, transmitted to client
$connection, the number of connection
$msec, the time with an accuracy to microseconds at the moment of the log entry
$pipe, "p" if request was pipelining
$request_length, the length of the body of the request
$request_time, the time of working on request in seconds
$status, status of answer
$time_local, local time into common log format.
The headers, transmitted to client, begin from the prefix "sent_http_", for example, $sent_http_content_range.

In the configuration there is always a predetermined format "combined":

log_format  combined  '$remote_addr - $remote_user [$time_local]  '
: '"$request" $status $apache_bytes_sent '
: '"$http_referer" "$http_user_agent"'

5.nginx日志管理的日志样例解释

日志格式

log_format  main  
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$connection $upstream_addr '
'$upstream_response_time $request_time';

nginx05 日志管理_nginx

图示样例解释

%remote_addr  请求来源的ip 100.116.26.57
$remote_user 远程访问的用户,一般为空
$time_local 请求访问的时间
$request 用于记录请求的url以及请求方法 POST /ebiz/third/ant.action?action=acceptInsurance HTTP/1.1
$status 请求状态 200 成功
$body_bytes_sent 给客户端发送的文件主体内容字节数904个字节
$http_referer 可以记录用户是从哪个链接访问过来的
$http_user_agent 用户代理 比如什么浏览器等 Jakarta Commons-Htt
$http_x_forwarded_for "110.75.248.252, 120.27.173.36" 多代理的服务器ip
$connection 连接数量113498954
$upstream_addr 10.151.0.234:7001


举报

相关推荐

0 条评论