Feedback on Nginx server block for a mail server (Postfix/Dovecot)

Hi all,

I would like to get a feedback for my Nginx configuration for supporting a mail server in FreeBSD. Currently I did setup the following to have my own mail server, but have a confusion on how to setup the server block in a non-premium Nginx (1.22.1) as I cannot use my mail client in my laptop to connect to SMTP.


1. DNS level: mail.example.com, NX: mail.example.com
2. Server level:
- Dovecot, Postfix, PostfixAdmin, with MySQL as storage.
- Got SSL certificate for mail.example.com and redirect port 80 to port 443 for mail.example.com.
- The server block for the Nginx is as following:
NGINX:
server {
      listen 443 ssl;
      server_name mail.example.com;
      ssl_certificate   ...
      ssl_certificate_key ...
      location / {
           proxy_pass localhost:25;
           proxy_set_header. Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme; 
      } 
}

Now from my mail client, it seems it can't connect to the SMTP, while I check the service is running and the DNS seems to be ok. Additionally one server block is sufficient for both Dovecot and SMTP?
 
This isn't a mail server, it's a web server. It has an open port on 443; HTTPS. Has nothing to do with SMTP. You cannot proxy the HTTP protocol to port 25, which uses the SMTP protocol. Those are two entirely different protocols.

Mail clients typically connect to port 587 to submit their mail, configure your postfix to accept mail on that port. Make sure to put some proper authentication in place or else your mailserver will end up getting abused.
 
  • Thanks
Reactions: etc
Back
Top