8

I am doing some testing with the NodeJS smtp-server module. It exposes a listening SMTP server on any specified port. SMTP usually runs on port 25, but in order to run the Node app as a non-root user, I am prevented from binding to ports below 1000.

Since I am already using nginx on this machine, I thought the simplest way to get around this would be to bind the server internally to a higher port, for example, 2500. Then use nginx to proxy the SMTP port (25) and directly pass through traffic to the internal listening port.

How can I configure nginx to proxy/passthrough incoming SMTP connections on port 25 to the port on which smtp-server is listening? In this case, incoming TCP connections on port 25 should be directly forwarded to localhost:2500.

Note that the smtp-server app already handles SMTP authentication, TLS, etc, so nginx should not attempt to do those operations. It should just pass the traffic directly through.

1
  • 1
    Just answered this here for a related, but not duplicate, question.
    – tanius
    Commented Jan 20, 2023 at 17:05

1 Answer 1

11

I figured it out:

Edit the /etc/nginx/nginx.conf file and add the following:

stream
{
        server
        {
                listen 25;
                proxy_pass 127.0.0.1:2500;
        }
}
1
  • not worked for me
    – erhan355
    Commented Mar 9, 2023 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .