简体   繁体   English

Apache日志中没有IP地址

[英]No IP address in apache logs

I have a apache server running on CentOS 6.5 server. 我有一个在CentOS 6.5服务器上运行的apache服务器。 In log files 25% of records are like this 在日志文件中,有25%的记录是这样的

000.000.000.000 - - [24/Jul/2014:04:15:10 +0000] "GET /address/of/the/page.html HTTP/1.1" 200 20341 "-" "Mozilla/4.0 

But rest of 75% of logs are like this, without IP 但是其余75%的日志都是这样,没有IP

- - [24/Jul/2014:04:15:10 +0000] "GET /address/of/the/page.html HTTP/1.1" 200 20341 "-" "Mozilla/4.0

Can somebody tell me what is the problem? 有人可以告诉我这是什么问题吗? Thanks! 谢谢!

By default Apache prints the REMOTE_ADDR header value in the access log, it may be that in your environment that value is blank in some cases. 默认情况下,Apache在访问日志中打印REMOTE_ADDR标头值,在某些情况下,可能是您的环境中该值为空。 You can try printing the X-Forwarded-For header in the access log and see if that has the values that you need. 您可以尝试在访问日志中打印X-Forwarded-For标头,查看该标头是否具有所需的值。

Typically if the requests are passing through proxy servers/load balancers its a good idea to check the value of the XFF header for the correct client IP. 通常,如果请求正在通过代理服务器/负载平衡器传递,则最好检查XFF标头的值以获取正确的客户端IP。

Hope this help. 希望能有所帮助。

-Avijit -AVIJIT

Complementing Avi's response, you will need to open the file /etc/apache2/apache2.conf and change the following lines: 为了补充Avi的响应,您需要打开文件/etc/apache2/apache2.conf并更改以下几行:

LogFormat "%v:%p %h %l %u %t \\"%r\\" %>s %O \\"%{Referer}i\\" \\"%{User-Agent}i\\"" vhost_combined LogFormat“%v:%p%h%l%u%t \\”%r \\“%> s%O \\”%{Referer} i \\“ \\”%{User-Agent} i \\“” vhost_combined

LogFormat "%h %l %u %t \\"%r\\" %>s %O \\"%{Referer}i\\" \\"%{User-Agent}i\\"" combined LogFormat“%h%l%u%t \\”%r \\“%> s%O \\”%{Referer} i \\“ \\”%{User-Agent} i \\“”组合

LogFormat "%h %l %u %t \\"%r\\" %>s %O" common LogFormat“%h%l%u%t \\”%r \\“%> s%O”常见

LogFormat "%{Referer}i -> %U" referer LogFormat“%{Referer} i->%U”引用

LogFormat "%{User-agent}i" agent LogFormat“%{User-agent} i”代理

to: 至:

LogFormat "%{X-Forwarded-For}i %v:%p %h %l %u %t \\"%r\\" %>s %O \\"%{Referer}i\\" \\"%{User-Agent}i\\"" vhost_combined LogFormat“%{X-Forwarded-For} i%v:%p%h%l%u%t \\”%r \\“%> s%O \\”%{Referer} i \\“ \\”%{User-代理} i \\“” vhost_combined

LogFormat "%{X-Forwarded-For}i %h %l %u %t \\"%r\\" %>s %O \\"%{Referer}i\\" \\"%{User-Agent}i\\"" combined LogFormat“%{X-Forwarded-For} i%h%l%u%t \\”%r \\“%> s%O \\”%{Referer} i \\“ \\”%{User-Agent} i \\“合并

LogFormat "%{X-Forwarded-For}i %h %l %u %t \\"%r\\" %>s %O" common LogFormat“%{X-Forwarded-For} i i%h%l%u%t \\”%r \\“%> s%O”常见

LogFormat "%{X-Forwarded-For}i %{Referer}i -> %U" referer LogFormat“%{X-Forwarded-For} i%{Referer} i->%U”引用

LogFormat "%{X-Forwarded-For}i %{User-agent}i" agent LogFormat“%{X-Forwarded-For} i%{User-agent} i”代理

Then, restart apache service with the command: sudo service apache2 restart and the client ip will appear on apache log. 然后,使用以下命令重新启动apache服务:sudo service apache2 restart,客户端ip将出现在apache日志中。 Check the result with: cat /var/log/apache2/access.log 使用以下命令检查结果:cat /var/log/apache2/access.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM