nginx php format,使用log_format为Nginx服务器设置更详细的日志格式

nginx服务器日志相关指令主要有两条,一条是log_format,用来设置日志格式,另外一条是access_log,用来指定日志文件的存放路径、格式和缓存大小,一般在nginx的配置文件中日记配置(/usr/local/nginx/conf/nginx.conf)。

nginx的log_format有很多可选的参数用于指示服务器的活动状态,默认的是:

log_format main

'$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

想要记录更详细的信息需要自己设置log_format,具体可设置的参数格式及说明如下:

参数

说明

示例

remote_addr

客户端地址

211.28.65.253

remote_user

客户端用户名称

time_local

访问时间和时区

18/Jul/2012:17:00:01 +0800

request

请求的URL和HTTP协议

“GET /article-10000.html HTTP/1.1”

http_host

请求地址,即浏览器中你输入的地址(IP或域名)

192.168.1.100

status

HTTP请求状态

200

upstream_status

upstream状态

200

body_bytes_sent

发送给客户端文件内容大小

1547

http_user_agent

用户终端浏览器等信息

“Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; GTB7.0; .NET4.0

ssl_protocol

SSL协议版本

TLSv1

ssl_cipher

交换数据中的算法

RC4-SHA

upstream_addr

后台upstream的地址,即真正提供服务的主机地址

10.10.10.100:8081

request_time

整个请求的总时间

0.205

upstream_reponse_time

请求过程中,upstream响应时间

0.002

#vim /usr/local/nginx/conf/nginx.conf

log_format main

//这边定义日志的名称为main,依据不同业务定义不同日志名称引用

'$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for '

'"$upstream_addr" "$upstream_status" "$upstream_response_time" "$request_time"';

include /usr/local/nginx/conf/vhost/*.conf;

#vim /usr/local/nginx/conf/vhost/web.conf

server

{

listen 80 default;

server_name www.it300.com;

index index.html index.htm index.php;

root /data/httpd/it300.com;

location ~ .*\.php?$

{

include fastcgi.conf;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 1h;

}

access_log /data/logs/it300.com.log main; //引用日志main格式

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值