Nginx mail proxy hides client’s ip

dovecotemail-servernginxPROXY

I successfully set up nginx imap/pop3 mail proxy with auth_http which has been working fine for months.
Recently came up a request on showing client's IP in mail.log at imap logins.

Since Nginx communicates with Dovecot the IP address in log belongs to Nginx server (which in this case 127.0.0.1 – as they are on the same server).

So far I could not find a solution or workaround for that.
Apparently not even logging is possible in nginx mail block.

The closest hit was a HAProxy support in Dovecot (https://wiki2.dovecot.org/HAProxy) but I am not sure there is similar to Nginx.

Any help is appreciated.

Thanks

Best Answer

Workaround

Not finding suitable solution I rather created a new log file in the proxy script which provided a acceptable solution to the request.

Here is the excerpt:

$fp = fopen('/var/log/mail_logins.log', 'a');
$now = "[" . (new \DateTime())->format('Y-m-d H:i:s') . "]";
fwrite($fp, $now . " HTTP_AUTH_PROTOCOL: " . $_SERVER["HTTP_AUTH_PROTOCOL"] . ", HTTP_AUTH_USER: " . $_SERVER["HTTP_AUTH_USER"] . ", HTTP_CLIENT_IP: " . $_SERVER["HTTP_CLIENT_IP"]. "\n");
fclose($fp);

It might help someone.

Related Topic