Please tell more
It boils down to having a special cname for each domain and an SRV-record.
You need to have a wildcard certificate registered to your domain (assuming you're some kind of hosting provider).
Let's say I have the domain "wolf.com".
Then I have a wildcard certificate "*.wolf.com"
Each client of mine has a "mail.<domain>" record which obviously points to one of your Plesk servers.
I will make sure that each domain also has a cname pointing to that record.
Let's say you're a client of mine with the domain janko.com
Your mail-server will be mail.janko.com
If you connect to the mail-server you will only get 1 certificate, namely *.wolf.com
That will not match with "mail.janko.com"
That's why we need a cname.
I automatically create a cname in my own zone for each of my client's domains.
For you that would be the cname
janko-com.wolf.com. IN CNAME mail.janko.com.
So that's the domain you need to use to connect with one of my mailservers.
Now we need an autodiscovery for that...
_autodiscover._tcp.janko.com. IN SRV 0 1 443 janko-com.wolf.com.
Which means that Outlook will connect to
https://janko-com.wolf.com/Autodiscover/Autodiscover.xml
Nginx will detect the regular expression in the domain with this directive
server_name ~^[a-z0-9-]+[a-z0-9]-[a-z0-9]+\.wolf.com$;
Because autoconfig (Thunderbird) does not need https you do not need to have a certificate and it becomes simpler.
autoconfig.janko.com. IN CNAME mail.janko.com.
cat /etc/nginx/conf.d/zz095_autodiscover.conf
Code:
server {
listen 8.8.8.8:80;
server_name ~^autoconfig\.[a-z0-9-]+\.[a-z0-9-]+$;
root /var/www/autoconfig_autodiscover;
index index.html;
error_log /var/log/nginx/autoconfig_autodiscover/error.log;
access_log /var/log/nginx/autoconfig_autodiscover/access.log combined;
location ~* /mail/config-v1.1.xml {
try_files $uri /config-v1.1.xml.php?$args;
rewrite ^(.+)$ /config-v1.1.xml.php?$1 last;
}
location ~ /config-v1\.1\.xml\.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SERVER_FQDN $host;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
server {
listen 8.8.8.8:443 ssl http2;
# mydomain.com = ^mydomain-com.wolf.com$
server_name ~^[a-z0-9-]+[a-z0-9]-[a-z0-9]+\.mr-wolf.nl$;
root /var/www/autoconfig_autodiscover;
error_log /var/log/nginx/autoconfig_autodiscover/error.log;
access_log /var/log/nginx/autoconfig_autodiscover/access.log combined;
ssl_certificate /root/.ssh/2018/2018.wildcard.wolf.com.pem;
ssl_certificate_key /root/.ssh/2018/2018.wildcard.wolf.com.key;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security $hsts_isd_header always;
#add_header Content-Security-Policy "default-src 'self';" always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
add_header X-Frame-Options SAMEORIGIN always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options nosniff always;
ssl_dhparam /etc/dhparam/dhparam4096.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
client_max_body_size 1m;
index index.php index.html index.htm;
location ~* /autodiscover/autodiscover.xml {
try_files $uri /autodiscover.xml.php?$args;
rewrite ^(.+)$ /autodiscover.xml.php?$1 last;
}
location ~ /autodiscover\.xml\.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SERVER_FQDN $host;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
cat /var/www/autoconfig_autodiscover/autodiscover.xml.php
Code:
<?php
preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", file_get_contents("php://input"), $matches);
$server = $_SERVER["HTTP_HOST"];
//set Content-Type
header("Content-Type: application/xml");
?>
<?php echo '<?xml version="1.0" encoding="utf-8" ?>'; ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<Account>
<AccountType>email</AccountType>
<Action>settings</Action>
<Protocol>
<Type>IMAP</Type>
<Server><?php echo $server; ?></Server>
<Port>993</Port>
<DomainRequired>off</DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName>
<SPA>off</SPA>
<SSL>on</SSL>
<AuthRequired>on</AuthRequired>
</Protocol>
<Protocol>
<Type>SMTP</Type>
<Server><?php echo $server; ?></Server>
<Port>587</Port>
<DomainRequired>off</DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName>
<SPA>off</SPA>
<AuthRequired>on</AuthRequired>
<UsePOPAuth>off</UsePOPAuth>
<SMTPLast>off</SMTPLast>
<Encryption>TLS</Encryption>
<TLS>on</TLS>
</Protocol>
</Account>
</Response>
</Autodiscover>
cat /var/www/autoconfig_autodiscover/config-v1.1.xml.php
Code:
<?php
header ("Content-Type:text/xml");
$mail = $_GET['emailaddress'];
$host = $_SERVER["HTTP_HOST"];
$domain = str_replace("autoconfig.","",$host);
$server = str_replace(".","-",$domain) . ".wolf.com";
echo <<<EOP
<?xml version="1.0"?>
<clientConfig version="1.1">
<emailProvider id="{$domain}">
<domain>{$domain}</domain>
<displayName>{$mail}</displayName>
<displayShortName>{$mail}</displayShortName>
<incomingServer type="imap">
<hostname>{$server}</hostname>
<port>143</port>
<socketType>STARTTLS</socketType>
<username>{$mail}</username>
<authentication>password-cleartext</authentication>
</incomingServer>
<outgoingServer type="smtp">
<hostname>{$server}</hostname>
<port>587</port>
<socketType>STARTTLS</socketType>
<authentication>password-cleartext</authentication>
<username>{$mail}</username>
</outgoingServer>
</emailProvider>
</clientConfig>
EOP;