#205·Nginx

mail auth module: Need Client-Port (and Server-IP and Server-Port)

Author: PHPGangstaCreated Sep 23, 2024Updated Sep 30, 2026
Labelsfeaturestale

Hello!

I'm using the mail module of nginx. The auth-HTTP-Request sends the following information:

GET /auth HTTP/1.0
Host: 127.0.0.1
Auth-Method: plain
Auth-User: user
Auth-Pass: password
Auth-Protocol: imap
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42

I need the Client-Port in my auth script for logging. I tried adding it with the following line in the mail>server block:

auth_http_header X-Client-Port $remote_port;

But I only receive

X-Client-Port: $remote_port

on my webserver, it looks like the variable is not replaced.

How can I get the Client-Port of the client in my auth script?

It could be fixed by generally replacing variables in the "auth_http_header" directive, or the "Client-Port" header should always be sent automatically to the auth script. Then I would also suggest to send "Server-IP"/"Local IP" and "Server-Port"/"Local Port" to the auth script, at the moment I add those two information via hardcoded directives:

auth_http_header  X-Server-IP    "10.0.1.1";
auth_http_header  X-Server-Port  993;

It would be nice to get rid of this because nginx has it built-in :-)