[edit] Solution
In addition to the instructions in the link, make the paths relative in frontend/config.json (in /srv/modoboa/instance)
{
"API_BASE_URL": "/api/v2",
"API_DOC_URL": "/api/schema-v2/swagger/",
"OAUTH_AUTHORITY_URL": "/api/o",
"OAUTH_CLIENT_ID": "blablabla",
"OAUTH_REDIRECT_URI": "/login/logged",
"OAUTH_POST_REDIRECT_URI": ""
}
and I also added this in the nginx conf, don’t remember if all was useful. In mail.domain2.com.conf
location ~ ^/(api|accounts|autodiscover) {
include uwsgi_params;
uwsgi_param UWSGI_SCRIPT instance.wsgi:application;
uwsgi_param Host $host;
uwsgi_param X-Forwarded-Host $host;
uwsgi_param X-Forwarded-Proto $scheme;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_pass modoboa;
}
...
location /radicale/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
...
}
As many have advised against it, I decided to start (almost self-)hosting my mail service.
I have tried with one domain, it has been running fine so far. I have not tested deeply but it works.
I want to host another domain, so I followed this guide which seems mostly still applicable: https://www.linuxbabe.com/mail-server/modoboa-multiple-domains
One thing though, with the current basic modoboa install, after following the steps in this guide, I can go to mail.domain2.com to access the webmail, however it is some kind of redirect and I end up on mail.domain.com. It must be on wsgi level because there is no redirect in nginx? So technically it’s still working since it’s what’s actually under the hood. But would it be possible to stay on mail.domain2.com?
Or maybe I have missed something somewhere, because unlike mentioned in the guide, it seems I have to use mail.domain1.com to set up client IMAP and not mail.domain2.com.
I know this is not a modoboa support community but I am not going to create one (yet) and I am not going to reddit. And I can’t open issues in Github. So live with it.
It sounds like you’ve been working on setting up a mail server with Modoboa, and you’re experiencing some issues with multiple domains. I’ll try to help you troubleshoot the problem.
Firstly, I’ll address the issue of the redirect from
mail.domain2.comtomail.domain1.com. This is likely due to the way you’ve set up your WSGI application. By default, Modoboa uses theHOSTenvironment variable to determine the domain name, which is then used to construct the URL for the webmail interface.To fix this issue, you can try setting the
MODOOBOA_HOSTNAMEenvironment variable in your WSGI application to the correct domain name. This will override the default behavior and allow you to access the webmail interface atmail.domain2.com.In your case, you can add the following line to your WSGI configuration file (e.g.,
instance.wsgi):os.environ['MODOOBOA_HOSTNAME'] = 'mail.domain2.com'This should fix the redirect issue and allow you to access the webmail interface at the correct domain name.
Regarding the issue with setting up client IMAP, it’s possible that you’re experiencing a conflict between the two domains. Modoboa uses a single database to store configuration and user data, so when you set up a new domain, it may overwrite some of the configuration for the existing domain.
To resolve this
It sounds like you’ve made great progress in setting up your self-hosted mail service with Modoboa. I’d be happy to help you troubleshoot the issues you’re experiencing.
Firstly, let’s address the redirect issue. It seems like the problem lies in the way Modoboa handles URL redirects. By default, Modoboa might be configured to redirect requests from one domain to another. This could be due to the
API_BASE_URLconfiguration in yourfrontend/config.jsonfile.To fix this, you can try setting the
API_BASE_URLto a relative path, as you’ve already done. However, you might also need to update theOAUTH_AUTHORITY_URLto point to the correct domain. For example:{ "API_BASE_URL": "/mail/domain2", "API_DOC_URL": "/mail/domain2/swagger/", "OAUTH_AUTHORITY_URL": "/mail/domain2/oauth", "OAUTH_CLIENT_ID": "blablabla", "OAUTH_REDIRECT_URI": "/mail/domain2/login/logged", "OAUTH_POST_REDIRECT_URI": "" }This should allow you to access the webmail interface at
mail.domain2.comwithout being redirected tomail.domain.com.Regarding the IMAP client setup issue, it’s possible that the guide you followed is outdated or incomplete. Modoboa does support multiple domains, but you might need to update the
settings.pyI’ve not used that software before, but a quick look at the guide makes me wonder if you have a https redirect in the nginx config. If that is hard coded to domain1 it will always redirect to it. Update it on the new config file to point to the right uri if that is the case.
Usually I setup with a single domain for the server, and use that for web mail, IMAP and SMTP certs. That way you don’t need to worry about the extra certificates needed for each domain (set your Mx to use the common name of your cert.)
The nginx conf has a https redirect, but I have a separate conf for domain2, and the redirect is correctly going to domain2.

