3

So I'm looking at setting up postfix and dovecot on a server that is currently hosting some web-sites via nginx, and I've stumbled upon the mail {} configuration option for nginx, but I'm having a hard time finding concrete examples that really show how I can use it.

Basically what I would like to do is have dovecot and postfix listen locally via sockets/ports on the current system (or another on the same local network if I move them in future), with nginx handling all of the actual external connections. Is this possible?

If so, what I'd also like to know is whether it's possible to use such a setup to support multiple domains?

For example, could I make something like the following work, and if-so, how?

mail {
    server_name mail.some.domain;

    ssl_certificate /some/path/mail.some.domain.pem;
    ssl_certificate_key /some/path/mail.some.domain.key;

    server {
        listen :587 ssl;
        listen [::]:587 ssl;
        protocol smtp;
        # somehow point this to postfix
    }

    server {
        listen :993 ssl;
        listen [::]:993 ssl;
        protocol imap;
        # somehow point this to dovecot
    }
}

mail {
    server_name mail.another.domain;

    ssl_certificate /some/path/mail.another.domain.pem;
    ssl_certificate_key /some/path/mail.another.domain.key;

    server {
        listen :587 ssl;
        listen [::]:587 ssl;
        protocol smtp;
        # somehow point this to postfix
    }

    server {
        listen :993 ssl;
        listen [::]:993 ssl;
        protocol imap;
        # somehow point this to dovecot
    }
}

i.e- nginx providing external connections for IMAP and SMTP for each domain, and routing to postfix and dovecot which are both configured with the appropriate virtual users, domains etc.

I know dovecot can handle multiple domains with individual certificates, so if it's easier to configure it separately then I can do that, but I'd like to be able to point different domains to postfix as well, without having to use a single certificate for all of my e-mail domains.

If possible I'd appreciate an answer that competes one of the above mail blocks, plus any configuration changes I might need for dovecot and/or postfix to work in this setup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.