APache logging

nicky s
nicky s used Ask the Experts™
on
if the request header has remote client ip  having null value, we should  not be printing in apache logs.  

need solution using setenv or setenvif & logformat and custom logs
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dr. KlahnPrincipal Software Engineer

Commented:
I would not think it is possible for Apache to have a null in the remote client IP address. Either the IPv4 or the IPv6 address should be present.

Could you show us a log excerpt showing an example of the problem requests?

Author

Commented:
From LB it is not printing the ip, when monitoring the for pages.
Dr. KlahnPrincipal Software Engineer

Commented:
Please show us a log extract showing both a normal log entry and one missing the IP address.  The only way I can think of to get an Apache log entry without an IP address is to use custom log formatting.
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Author

Commented:
the actual requirement is if the request contains Xforward for IP and SM_USER header then use only type of Custom loggin otherwise use combined logging
Principal Software Engineer
Commented:
Unfortunately logging formats can't be switched back and forth while Apache is running.  Either combined logging or custom logging can be used, but only one and this is set and fixed at startup.  It is not possible to switch back and forth between them using environment variables.

Logging can be turned off completely for individual requests but it's all or nothing; see the example below.  Also see

https://httpd.apache.org/docs/current/mod/mod_log_config.html

"A log format is specified, and the logging can optionally be made conditional on request characteristics using environment variables."  Logging can be made conditional, but not the format.

CustomLog /var/log/apache/access_mysite locallog env=!nonlog-request

SetEnvIfNoCase User-Agent Googlebot nonlog-request
SetEnvIfNoCase User-Agent Slurp nonlog-request
SetEnvIfNoCase Request_URI favicon\.ico$ nonlog-request
SetEnvIfNoCase Request_URI \.gif$ nonlog-request
SetEnvIfNoCase Request_URI \.jpg$ nonlog-request

Open in new window

Author

Commented:
that answers my question. thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial