【10.17】nginx 访问日志、静态文件不记录、过期缓存、日志切割、防盗链

【10.17】nginx 访问日志、静态文件不记录、过期缓存、日志切割、防盗链

4.38 nginx访问日志

访问日志:用户访问网站的记录

主要就是配置路径加格式

  • 1、配置方法:
    1)、主配置文件 /etc/nginx/nginx.conf 中,定义日志格式
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

对应变量含义:

变量 含义
$remote_addr 客户端IP(公网IP)
$http_x_forwarded_for 代理服务器的IP
$time_local 服务器本地时间
$host 访问主机名(域名)
$request_uri 访问的url地址
$status 状态码
$http_referer referer
$http_user_agent user_agent

长用全局变量汇总:https://blog.csdn.net/arsenal4life/article/details/102616484

2)、虚拟主机配置 /etc/nginx/conf.d/bbs.ars4life.com.conf 的最下方,加入一行 access_log

access_log  /data/logs/bbs.ars4life.com.access.log  main;

用于定义访问日志
2、改好配置后,需要创建 /data/logs/ 目录,否则会报错

[root@alexis-01 ~]# mkdir /data/logs/
[root@alexis-01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@alexis-01 ~]# nginx -s reload
[root@alexis-01 ~]# cat /data/logs/bbs.ars4life.com.access.log

3、访问网页后,日志会产生以下内容

[root@alexis-01 ~]# cat /data/logs/bbs.ars4life.com.access.log
192.168.194.1 - user1 [17/Oct/2019:22:13:47 +0800] "GET /forum.php?mod=forumdisplay&fid=2 HTTP/1.1" 200 26614 "http://444444.com/forum.php?gid=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
192.168.194.1 - user1 [17/Oct/2019:22:13:47 +0800] "GET /data/cache/style_1_forum_forumdisplay.css?fv2 HTTP/1.1" 304 0 "http://444444.com/forum.php?mod=forumdisplay&fid=2" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
192.168.194.1 - - [17/Oct/2019:22:13:47 +0800] "GET /static/image/common/fall.png HTTP/1.1" 301 169 "http://444444.com/data/cache/style_1_forum_forumdisplay.css?fv2" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Geck
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值