Nginx 访问日志配置

Nginx 会把每个用户访问网站的日志信息记录到指定的日志文件里,此功能由 ngx_http_log_module 日志模块负责。

语法:

log_format  name  string  ...;      //定义日志格式,log_format是固定关键字,name是日志格式的名字,string是日志变量
access_log  file  name;             //应用日志格式,access_log是固定关键字,file是存放日志的路径,name是应用哪个名字的日志格式

日志变量:

$remote_addr :记录访问网站的客户端地址
$remote_user :记录远程客户端用户名称
$time_local :记录访问时间
$request :记录用户的 http 请求起始行信息
$status :记录请求返回的状态码
$http_referer :记录此次请求是从哪个链接访问过来的,可以根据 referer 进行防盗链设置
$http_user_agent :记录客户端访问信息,如浏览器、手机客户端等

配置实例:在主配置文件的HTTP区块中定义日志格式,然后在各个虚拟主机(即Server区块下)应用日志格式

worker_processes  1;
user nobody nobody;
pid /usr/local/nginx/nginx.pid;error_log logs/error.log error;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;       log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘                                         ‘$status $body_bytes_sent "$http_referer" ‘                    ‘"$http_user_agent" "$http_x_forwarded_for" ‘;
    server {
        listen       80;
        server_name  www.xxxxx.com;
        location / {
            root   html/www;
            index  index.html index.htm;
        }        access_log logs/access_www.log main;
    }
}
时间: 2024-08-25 07:28:50

Nginx 访问日志配置的相关文章

nginx访问日志配置+日志切割+不记录静态文件日志+设置静态文件过期时间

nginx访问日志 查看nginx.conf文件 vim /usr/local/nginx/conf/nginx.conf 中间有一行是定义log的格式 log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"';

Linux学习总结(四十一)nginx 访问日志配置,网页缓存有效期配置

我们在学些apache的时候已经接触过访问日志,还记得日志格式在哪里定义吗,在httpd的主配置文件中,/usr/lcoal/apache2.4/conf/httpd.conf 搜索LogFormat 就可以查看到,系统给了我们两种格式,combined 和common 我们选择使用了combined ,它记录的信息更全面.接下来我们在虚拟主机配置文件中定义了日志所在路径及类型./usr/local/apache2.4/conf/extra/httpd-vhosts.conf 1访问日志 在ng

ELK+syslog+nginx访问日志收集+分词处理

一.nginx访问日志配置: 1.日志格式配置: log_format json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"xff":"$http_x

elkstack实战---集中管理nginx访问日志及报表展示

一.nginx访问日志,格式调整为json # cat /opt/config/tengine/nginx.conf |grep json log_format json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"method":"$request_method",' '"url":&quo

Nginx 访问日志增长暴增出现尖刀的详细分析

前言:          Nginx日志里面Mobileweb_access.log增长特别大,一天上百兆,将近100W的访问记录,按照我们目前的规模,热点用户才500个左右,就算人人用手机app访问,怎么可能会有这么大的url访问量?以前只是安装使用nginx,还没有抽出时间仔细研究,这回需要彻底的去分析nginx日志了. 1,日志分类 主要2种,一种是错误日志,一种是访问日志,这些配置都在/usr/local/nginx/conf/nginx.conf里面,默认都是打开的,自己也可以选择关闭

Nginx访问日志、Nginx日志切割、静态文件不记录日志和过期时间介绍

Nginx访问日志 1. 进入配置文件 [[email protected] src]# vim /usr/local/nginx/conf/nginx.conf  //搜索log_format 参考更改配置成如下: log_format aming '$remote_addr $http_x_forwarded_for [$time_local]' 如图: 日志格式字段含义如下: combined_realip为日志格式的名字,后面可以调用它. 2.到虚拟主机配置文件中指定访问日志的路径 [[

2018-3-14 12周3次课 Nginx访问日志、日志分割、日志不记录静态文件和过期时间

12.10 Nginx访问日志 ·日志格式: [[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf 搜索log_format (虽然红框中有三行,但实际上时一行配置,以分号为结尾) combined_realip 定义日志格式名字,此处定义成什么,那么后面引用时就要写成什么 公网ip(出口ip) ·除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加 access_log /tmp/1.log co

LNMP(2)Nginx默认虚拟主机、Nginx用户认证、Nginx域名重定向、Nginx访问日志、

Nginx默认虚拟主机 Nginx和httpd都有虚拟主机,在httpd中第一个被加载的就是默认虚拟主机:但是在Nginx中它有一个配置用来标记默认虚拟主机(default_server),如果不做标记,那么第一个也是默认为虚拟主机. 默认虚拟主机设置: 1.需改配置文件/usr/local/nginx/conf/nginx.conf cd /usr/local/nginx/conf/ vim nginx.conf 删除内容后,加上一行(在httpd{}里加)include vhost/*.co

48.Nginx访问日志、Nginx日志切割、静态文件不记录日志和过期时间

一.Nginx访问日志 日志格式 vim /usr/local/nginx/conf/nginx.conf //搜索log_format combined_realip //规则名字 除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加 vim /usr/local/nginx/conf/vhost/test.com.conf 添加 access_log /tmp/1.log combined_realip; 这里的combined_realip就是在nginx.