默認的log日誌格式在主配置文件 httpd.conf 中能夠看到:前端
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common
其中 %h 是記錄訪問者的 IP,若是在 web 的前端有一層代理,那麼這個 %h 其實就是代理機器的 IP,這不是咱們想要的。在這種狀況下,%{X-FORWARDED-FOR}i 字段會記錄客戶端真實的ip。因此配置文件改成:
web
LogFormat "%h %{X-FORWARDED-FOR}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common