Nginx的日志配置在/usr/local/nginx/conf/nginx.con配置文件中
http {
include mime.types;
default_type application/octet-stream;
log_format main ' "$remote_addr" "$upstream_addr" "[$time_local]" "$request_time" "$upstream_response_time" "$status" "$sent_http_error_code" "$content_length""$body_bytes_sent" "$http_request_id" "$request" "$http_user_agent" "$http_host" "$server_addr"';
access_log logs/access.log main;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
其中注释的内容为默认的配置:
1.$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;
2.$remote_user :用来记录客户端用户名称;
3.$time_local : 用来记录访问时间与时区;
4.$request : 用来记录请求的url与http协议;
5.$status : 用来记录请求状态;成功是200,
6.$body_bytes_s ent :记录发送给客户端文件主体内容大小;
7.$http_referer :用来记录从那个页面链接访问过来的;
8.$http_user_agent :记录客户端浏览器的相关信息;
其中:access_log logs/access.log main; 为日志的路径及文件名在以nginx为根目录的相对路径
未注释的是自定义的配置
"$remote_addr" :客户端IP地址
"$upstream_addr" :服务端代理的IP的IP的地址
"[$time_local]" :当前时间
"$request_time" :请求时间
"$upstream_response_time" :响应时间
"$status" :响应状态值
"$sent_http_error_code" :错误的状态值
"$content_length" :请求的内容的length
"$body_bytes_sent" :
"$http_request_id" : "-"
"$request" :请求头信息
"$http_user_agent" :-
"$http_host" :请求的域名
"$server_addr"'; :Nginx的IP地址
输出的例子:
"172.28.6.131" "172.28.6.133:8081" "[25/May/2015:14:05:04 +0800]" "0.004" "0.004" "200" "-" "308""342" "-" "POST /remoting/xxxxServiceCall HTTP/1.1" "-" "rpc.xxx.test.com" "172.28.6.120"
配置如下:
upstream rpc.xxx.systoon.com{
server 172.38.6.135:8081;
server 172.38.6.136:8081;
server 172.38.6.137:8081;
}
server {
listen 80;
server_name rpc.xxx.systoon.com;
location / {
proxy_pass http://rpc.xxx.systoon.com;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
在/etc/hosts文件中配置域名Ip地址映射例如:
127.0.0.1 localhost