Mail TLS and authentication service
Separate client TLS from the authentication hop
Implicit TLS starts encryption immediately; STARTTLS (STLS for POP3) upgrades a protocol connection. Prefer a required upgrade on a designated upgrade listener, or an implicit TLS listener with a verified certificate. Client TLS does not encrypt the separate HTTP authentication request or guarantee encrypted traffic to the backend. Keep those paths private and assess their security independently. This is a fragment for an IMAP implicit TLS listener inside mail, requiring locally generated certificates.
server { listen 127.0.0.1:19381 ssl; protocol imap; ssl_certificate certs/mail.pem; ssl_certificate_key certs/mail.key; ssl_protocols TLSv1.2 TLSv1.3;}Require a TLS upgrade when appropriate
On a separate IMAP listener without the ssl parameter, starttls only requires the TLS upgrade before authentication. The certificate settings must also be present or inherited. Do not mix the implicit TLS and upgrade modes on the same socket. TLS hostname and chain verification remain client responsibilities. The fragment does not configure the authentication service or backend.
server { listen 127.0.0.1:19384; protocol imap; starttls only; ssl_certificate certs/mail.pem; ssl_certificate_key certs/mail.key; ssl_protocols TLSv1.2 TLSv1.3;}Read the authentication decision
The auth_http protocol carries authentication metadata in HTTP headers; sensitive fields can include passwords. Do not record or expose the request. The authentication service evaluates identity and returns an approved backend address and port, or a failure message. The response body is ignored. HTTP 200 alone is not successful mail authentication. These are synthetic response transcripts; no credentials or real mail service are used.
HTTP/1.0 200 OKAuth-Status: OKAuth-Server: 127.0.0.1Auth-Port: 19385
HTTP/1.0 200 OKAuth-Status: Login deniedBound failure and trust
The auth endpoint must be reachable only through a trusted channel, and its destinations must come from a fixed approved inventory. Set a finite auth_http_timeout. For failures, omitting Auth-Wait causes a connection-closing error; repeated failures must be bounded. Do not use client-provided strings as destinations, trust arbitrary forwarded identity, or log authentication headers. This offline fixture models already-evaluated decisions only; it is not an authentication implementation.
auth_http http://127.0.0.1:19380/auth;auth_http_timeout 3s;# Inside mail or mail server; private fixture endpoint only.Practice and next steps
Practice: Using the offline fixture, classify an approved IMAP decision, denied identity, wrong protocol and unapproved destination. Explain why HTTP 200 is insufficient. Next lesson: nginx-specialist-modules.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Mail TLS and authentication service
Explain trust and external auth requirements
What does starttls only require on an upgrade listener?
Which response field signals a successful decision?
Does TLS on the client listener protect the auth HTTP hop automatically?
What should select the backend destination?
Why omit Auth-Wait on terminal failure?