Nginx 用log_format设置日志格式
2016-03-04 10:05
731 查看
1、配置文件
#vim /usr/local/nginx/conf/nginx.conf
log_format access ‘$remote_addr – $remote_user [$time_local]
“$request” ‘‘$status $body_bytes_sent “$http_referer”
‘‘”$http_user_agent” $http_x_forwarded_for’;
include /usr/local/nginx/conf/vhost/*.conf;
2、vhost中配置文件
#vim
/usr/local/nginx/conf/vhost/web.conf
server
{
listen 80 default;
server_name www.linuxidc.com;
index index.html index.htm index.php;
root /data/httpd/linuxidc.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 /usr/local/nginx/logs/access.log
access;
}
3、相关说明解释
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
:记录客户端浏览器的相关信息;linux
#vim /usr/local/nginx/conf/nginx.conf
log_format access ‘$remote_addr – $remote_user [$time_local]
“$request” ‘‘$status $body_bytes_sent “$http_referer”
‘‘”$http_user_agent” $http_x_forwarded_for’;
include /usr/local/nginx/conf/vhost/*.conf;
2、vhost中配置文件
#vim
/usr/local/nginx/conf/vhost/web.conf
server
{
listen 80 default;
server_name www.linuxidc.com;
index index.html index.htm index.php;
root /data/httpd/linuxidc.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 /usr/local/nginx/logs/access.log
access;
}
3、相关说明解释
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
:记录客户端浏览器的相关信息;linux
相关文章推荐
- 使用socket方式连接Nginx优化php-f…
- mac下安装使用brewhome安装nginx
- 实战Nginx与PHP(FastCGI)的安装…
- nginx 正则表达式匹配入门篇
- Nginx Proxy buffer 工作原理
- nginx内置全局变量及含义
- nginx/windows: nginx多虚拟…
- nginx的 CPU参数worker_proce…
- nginx的valid_referers指令防盗链
- Nginx+CI框架出现404错误怎么解决
- ubuntu+nginx+php7+mysql 安装
- Nginx配置Restful风格url
- nginx上搭建HLS流媒体服务器
- LNMP第二部分nginx、php配置
- nginx配置文件nginx.conf解读
- 发现一个nginx LUA开发Web App的框架
- Scaling CloudFlare’s Massive WAF
- centos6 yum 安装nginx 不成功解决办法
- nginx 同一端口根据不同域名转发到不同端口
- Nginx+CI出现404错误