美文网首页Nginx
Nginx访问日志(access_log)配置及信息详解

Nginx访问日志(access_log)配置及信息详解

作者: IARNO | 来源:发表于2018-11-22 23:10 被阅读0次

通过访问日志,可以知晓用户的地址,网站的哪些部分最受欢迎,用户的浏览时间,对大多数用户用的的浏览器做出针对性优化。

Nginx中相关日志配置详解

image.png
  • 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:访问网站的客户端地址
       $remote_user:客户端用户名
       $time_local:访问时间和时区
       $request:http行信息
       $status:状态码,如200,404等
       $body_bytes_sent :服务端发送给客户端的响应body字节数
       $http_referer:记录哪个链接访问过来的,可以根据参数进行防盗链设置
       $http_user_agent:客户端访问信息,如浏览器、手机客户端等
       $http_x_forwarded_for:当前端有代理服务器时,设置web节点记录客户端地址的配置,此参数生效的前提是代理服务器也要进行相关的x_forwarded_for设置

  • access_log #访问日志路径,可在当个虚拟主机(nginx配置的server块)中配置
#access_log  logs/access.log  main;

access_log参数:
       logs/access.log:访问日志路径
       main:log_format中的main(日志格式名,可自定义)

详解 $http_x_forwarded_for

image.png
  • 当中间有一层方向代理时访问日志中$remote_addr参数其实是方向代理服务的地址,而$http_x_forwarded_for才是真正的用户地址。

相关文章

网友评论

    本文标题:Nginx访问日志(access_log)配置及信息详解

    本文链接:https://www.haomeiwen.com/subject/hvnrqqtx.html