Mail Proxy with Multiple Mail Domains
nsclick at gmx.de
nsclick at gmx.de
Wed Nov 13 19:00:58 UTC 2019
Hello,
I would like to setup a Nginx mail proxy which handles IMAP and SMTP for two different mail domains and two different backend servers (one server for each of the domains).
Let's say we have the two mail domains:
- mail.foo.com
- mail.bar.com
Then we can setup a minimalistic mail block like:
mail {
server_name mail.foo.com; <-- ############ Can I simply add 'mail.bar.com' here? ############
auth_http localhost/nginxauth.php;
server {
listen 25;
protocol smtp;
}
server {
listen 143;
protocol imap;
}
}
And a minimalistic nginxauth.php script like:
<?php
/*
Variables we have here:
$_SERVER["HTTP_AUTH_USER"]
$_SERVER["HTTP_AUTH_PASS"]
$_SERVER["HTTP_AUTH_USER"]
$_SERVER["HTTP_AUTH_PASS"]
$_SERVER["HTTP_AUTH_PROTOCOL"]
*/
if ($protocol=="imap")
{
$backend_port=143;
}
if ($protocol=="smtp")
{
$backend_port=25;
}
$backend_ip["mailhost_foo"] ="192.168.1.10";
$backend_ip["mailhost_bar"] ="192.168.1.20";
$selection <-- ############ How to make this selection? ############
Do we have information about the requested mail domain here?
If yes, in which $_SERVER item?
header("Auth-Status: OK");
header("Auth-Server: $backend_ip[$selection]");
header("Auth-Port: $backend_port");
?>
But how to solve the questions marked with "###" above?
I tried to find something in the Nginx documentation, but without success.
Any ideas?
Thanks a lot in advance.
More information about the nginx
mailing list