Need help with mail server

Okay so I have a domain that is from Namecheap but pointed to Cloudflare. My website is running with Nginx as a server in my Ubuntu 20.04 LTS. Everything is working fine. But now I am trying to set up a mail server in my VPS with the help of Docker and Dockerized Mailcow in this particular domain

I have installed and setup everything from a tutorial from Youtube and the part where it says to go to the browser and type the hostname (which is the FQDN and I put mail.example.com as my FQDN) I don’t get it but the tutorial shows Mailcow’s interface.

My VPS’s hostname is server1.something.com. And I have added mail.example.com in /etc/hosts as 127.0.0.1 mail.example.com localhost localhost.localdomain. In CF I have mail added as A record which points to my VPS and MX record with content mail.example.com.

Now when I visit mail.example.com I don’t see Mailcow interface.

What could be going wrong here? Am I missing something? Do I need add something to my Nginx configuration for the domain?

Do you see something? Or is your browser unable to connect?

I see a fallback html page which I set up for another domain in Nginx.

Then there’s an error in your nginx configuration. Did you add a server {} block for the mail subdomain?

No I haven’t. I thought of doing that by following Nginx’s official docs for mail server. But there is this line:

server_name mail.example.com;
auth_http   localhost:9000/cgi-bin/nginxauth.cgi;

And I don’t know what I should put instead of localhost:9000. My actual website for the domain is running on port 3000.

And I don’t know if I should create a new block in my domain’s config file as server{} or in nginx.conf file’s mail{} block

You’re trying to make the mailcow web interface accessible at mail.example.com, correct?

Yes that is correct. but I’m not sure if my configurations for Nginx or CF is correct or not

Alright. Assuming the Docker container is exposing a port on the host, you’ll have to create a server {} block (with a valid SSL certificate :wink:) and include this:

location / {
    proxy_pass http://127.0.0.1:<container port>/
}

I’d recommend you set the DNS record for mail.example.com to DNS only :grey:. Then once your setup is working, change the record to proxied :orange:.

If you need further help with nginx configuration I’d recommend you ask on Reddit or StackOverflow. This forum is meant to provide help with Cloudflare products and services so debugging nginx configs is a bit beyond the scope :slightly_smiling_face:

Thanks for your detailed answer. However I have last two questions. Please bear with me.

  1. Should I create the server block in nginx.conf file? If yes, then how can I create multiple mail servers for different domains?
  2. Where will I get container port for the proxy pass? I ran sudo docker ps and there are so many ports mentioned.

Please help me out with these questions and I’ll go away and leave you be.

Sorry, it’s a long time since I’ve last used nginx. That’s a question better asked on Reddit or StackOverflow.

There’s probably a port 80, 8000 or 8080 being exposed. The mailcow docs should tell which ports do what :slightly_smiling_face:

Thanks for your time.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.