Nginx访问日志
日志格式咱们能够在主配置文件看到css
#vim /usr/local/nginx/conf/nginx.conf //搜索log_format
$remote_addr 客户端ip(公网ip)
$http_x_forwarded_for 代理服务器ip
$time_local 服务器本地时间
$host 访问主机名(域名)
$request_uri 访问的uri地址
$status 状态码
$http_referer referer
$http_user_agent user_agentnginx
除了在主配置文件nginx.conf里定义日志格式外,还须要在虚拟主机配置文件中增长 access_log /tmp/1.log combined_realip;
#vim /usr/local/nginx/conf/vhost/test.com.conf
这里的combined_realip就是在nginx.conf中定义的日志格式名字 vim
# /usr/local/nginx/sbin/nginx -t //检测语法
#/usr/local/nginx/sbin/nginx -s reload //从新加载
#curl -x127.0.0.1:80 test.com -I //测试
cat /tmp/1.log //查看日志的格式
静态文件不记录过时时间
#vim /usr/local/nginx/conf/vhost/test.com.conf//写入以下内容
配置以下服务器
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 7d; //记录过时时间 access_log off; //不记录访问日志 } location ~ .*\.(js|css)$ { expires 12h; access_log off; }
# /usr/local/nginx/sbin/nginx -t //检测语法
#/usr/local/nginx/sbin/nginx -s reload //从新加载