Searching for some gurus to clarify and discuss some of the procedures involved in Nginx Reverse Mail Proxy, its limitations and best practices for upstream servers, load balancing and other applications. There seems to be very little accurate discussion on this topic which is an excellent feature of Nginx that many other servers do not offer. The nginx documentation is essentially an overview lacking depth. Perhaps the expertise found in this forum can clarify:
Compiling Nginx with the required modules for reverse mail proxy.
Loading the modules correctly in the configuration.
Creating the required authentication server or script & advantages, disadvantages.
Upstream server TLS options. Termination at proxy versus upstream MTA server.
Alright that should cover steps 1 & 2. Let’s move on to Creating the required authentication server or script & advantages, disadvantages. Although many have used basic authentication (auth_basic) in nginx to restrict access to websites, specific directories, or pages, few have created a dedicated authentication server or created local scripts for a reverse mail proxy using the auth_http directive. This is where further discussion would be helpful in both concept, clarification and procedural methods. It is my hope someone with experience in this area can add to the topic.
do you have a specific task or is more of a exploration project? nginx is meant to be used in front of postfix/dovecot. They create processes per user session. So to reduce the load on mail daemon nginx is introduced to allow only authenticated traffic.
Without authentication nginx won’t know where to proxy a connection.
As for TLS - you can’t terminate client TLS at MTA, cause you have to authenticate the session. And as with most other upstreams - MTA is trusted. So if it behaves - nginx may fail.
I haven’t used mail module too much but try me, I can probably help you with some basics.
Awesome thanks for your response. It’s more of a clarification project to enhance the official documentation. I think one of the more common scenarios is the use of nginx (mail modules enabled) on an edge server that terminates the ssl and then proxies the SMTP, IMAP, or POP protocols to one or more MTA servers (load balancing etc). The confusion seems to lie in why there is an additional authentication server required by nginx to simply proxy the traffic mail protocols when this isn’t the case for normal HTTP proxies. The nginx mail directive in the server config directs the traffic to the correct MTA location and the MTA authenticates its own connections ( traffic sent from edge to MTA servers is unencrypted ). It would be great to have clear examples of creating the required authentication server, or alternatively creating a script that handles it as mentioned in the documentation which simply mentions the necessity. What are the advantages of an authentication server vs a script? The Nginx authentication seems redundant. I’ve always wanted to try the Nginx mail proxy, but instead have simply used iptables to forward to the MTA’s that handle their own SSL termination.
Hey all! Just popping in here to say that if you have any suggestions on how to improve the documentation please feel free to open an issue or PR in our nginx.org repo!
yes I think we need much better documentation and walk through on creating authentication server/script requirements. The Mail server will always be the actual authentication for its imap and smtp protocols. The official documentation does not cover this in detail.