For the life of me, I couldn't get mod_remoteip to get client IPs in my Apache access logs. I'm working on a Virtualmin setup with Varnish 4 installed in front of Apache 2.4.7. How do you get it working?
相关问题
- Stop .htaccess redirect with query string
- I want to trace logs using a Macro multi parameter
- Error message 'No handlers could be found for
- .htaccess rule, redirecting old unexistent address
- convert logback.xml to log4j.properties
相关文章
- Apache+Tomcat+JK实现的集群,如果Apache挂了,是不是整个服务就挂了?
- how do I log requests and responses for debugging
- How reliable is HTTP_HOST?
- Making a two way SSL authentication between apache
- Android Studio doesn't display logs by package
- UnicodeEncodeError when saving ImageField containi
- mod_rewrite only on GET
- Stacktrace does not print in Glassfish 4.1 Cluster
I finally got the client IPs in the log and I found the last step here:
Here are the steps to getting it to work:
Get Varnish to pass a header to Apache with the client IP. You do this by including this bit of code (found in this answer) at the very beginning of your vcl_recv:
Now enable mod_remoteip in Apache.
Edit your Apache config to tell mod_remoteip what header contains the client IP (from Apache docs). I'm using X-Forwarded-For, but I suppose this could be anything as long as it matches what you've configured Varnish to pass along:
RemoteIPHeader X-Forwarded-For
If you restarted Apache and Varnish right now, I bet Apache will now reference the client IP instead of 127.0.0.1 everywhere. Except in the access logs which is where I've been checking. To get the access logs to show the client IP, we need to modify the log format Apache it's using. In my case, this was the "combined" format. This was my breakthrough and I found it here which links to this excellent information for our purposes.
This is what my combined log format looked like:
And I just substituted %a in where %h was and this is what it looks like:
And finally, here's what a block of my Apache config file looks like (mod_remoteip loading prior to it):