Subdomain cert creation


i just rebuilt one server and set hostname to

Everything went smooth up to the letscencrypt thing.

I git’ed the code from letsencrypt in to folder /opt/letsencrypt/ and added /opt/letsencrypt/letsencrypt-auto to module config for Webmin.

Then i wanted to generate a system certificate and i got an errormessage, that i would need a virtual host for this.

So i created a virtual host for it and tried it again. Although apache is running and if i enter in my browser window it will show apache’s default page, the letsencrypt creates w a 404 error:

Type: unauthorized
Detail: Invalid response from
Od3muYoLGcaK0hj1qKInN5Y9JIg []: 404

I’ve also read in various places, that it could be a problem, when i redirect the http:// to https:// which i didn’t do right now, but would like to.

So how to fix that or do i have to follow another best practice?

Thanks and best

I’ve seen this: but it seems it doesn’t apply:

To elaborate a little more.

It makes sense in my eyes, having as the servers hostname and for postfix. i would like to use as serverwide mailserver address with postfix and dovecot certs; i also want to setup PFS for mailserver too. But if i can’t create certs for, i can’t use them for mailserver.

i have pointed the subdomain server02 as an A Record to the IP of this server. Would i need an mx record for server02 as well, pointing it to the same IP?

Update: I created a new subdomain and pointed it to the IP of server02, created a virtual host and guess what? The cert has been created. So why wouldn’t it for server02?

And why does letsencrypt give back a 404 for server02, when the default apache website is being shown?

I also want to use for systemwide scripts like phpmyadmin, roundcube etc, therefore it makes sense in my eyes having also a virtual server with Or will webmin/virtualmin being confused with that?

For one virtual host on that server i need this directive for apache:

Header add Access-Control-Allow-Origin "*"

Since that virtual host should run under https, i would add this to the 443 section of the conf file and do an htaccess rewrite like this:

RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

which i would use on every virtual host, since every virtual host should be only accessible via https.

So any insight is truly appreciated, perhaps i am barking up the wrong tree?

Thanks and best

PS: i am using Ubuntu 14.04 and, interestingly enough, i still have the problem, that the ftp daemon dies almost any day. i have tried in another installation to have a watchdog check on ftp and restart it, when it has gone, but this doesn’t always work. So anyone, please?


i haven’t found a package in the official repos and was following a tutorial in the web; where it was said you would have to git it.

With another subdomain everything went smooth with letsencrypt creation. it is just server2 with problems. Btw, when i checked automatic renewal in webmin, and gave him 2 months, it wouldn’t work at all with the subdomain. I also entered just, not; then it went through

I got another one concerning this: I have a application with a different home directory (in fact /opt/rm/public ) which i would also like to serve with https. Given, that i change that paths in its config file under available sites, where should i place the certfiles then, if the root directory is somewhere else?

I also think that i found out, what is happening:

If i enter server02 etc… in my browser, it will show the content of the var/www/html folder. And not /home/server02/public_html.

Therfore the server is sort of confused; because the hostname is server02… and there is a virtualhost for server02 too.

But the cert creation feature of Webmin told me in order to have letsencrypt certs for my hostname server02.etc… i would need a virtual host. Sorta confusing.

So, what to do? I could delete the server02 virtualhost and setup everything like server02… roundcube and server02 etc scripts manually, and not with the scriptinstaller from virtualmin.

Thank you very much for pointing this out,

PS: Could you please anonymize the server in your post? Thanks.

So, let’s go through this…

  • Is there a reason you checked out letsencrypt manually instead of installing the official package (I assume Ubuntu provides one?)
  • Yes, if you redirect HTTP to HTTPS and you have no proper TLS setup, boulder (letsencrypts automatic CA-Server) won’t be able to check for the acme challenge. Technically you can force the challenge to happen over TLS, then you’d have to serve HTTPS and couldn’t request a certificate without it. But afaik the normal challenge should gracefully handle being upgraded to HTTPS via a redirect from the server, so you shouldn’t run into issues with your setup once TLS is properly set up (even with a self-signed cert).
  • Create a file/.well-known/acme-challenge/test in the document root of the server02 virtual host. Can you access it through the browser? What do the apache access/error logs say?
  • Webmin/Usermin run on entirely different ports and shouldn’t be confused because of the virtual host. Of course if you want to run different services on one virtual host they have to be distinguishable in a way, so you can for example do https://host.domaintld/roundcube/ by placing the roundcube directory in its own subdirectory within the virtual host document root.
  • Your apache directives seem to be ok to me.
  • If you really want everything to be HTTPS it can be a PITA to get letsencrypt to properly place all acme challenges into the document roots of all virtual hosts. To work around that you can redirect all the challenges to the same virtual host and make letsencrypt give you one SAN certificate for all your (sub)domains: Read here. This also makes it easy to just use a new subdomain for each new service (like roundcube on webmail.domain.tld)

The certificates should never leave the /etc/letsencrypt directory! Just point the virtual host SSLCertFile/SSLKeyFile/etc to the certificate files that are stored there in /etc/letsencrypt/live/ Regarding the /opt/... website you may get problems because of suexec by not placing the document root under the /home directory of the user for which you set up the domain. You’ll have to try that out.

Yes, apache, by default, points ServerName to the default document root /var/www/html and because that is a global configuration it takes precedence over the virtualhost you created. Name-clashing a Virtual Server with the server hostname is something that most likely cannot be handled properly by virtualmin (there’s just too much uncertainty as to what the user actually wants to happen. And programmatically it seems like it would require a lot of edge case handling in various different parts of the code, so it’d probably be best if virtualmin throws an error or a warning if someone tries to do this).

So yes, you could go the manual way and not use a Virtual Server and probably won’t be able to use the install scripts.

Or you could trick virtualmin by pointing the default document root to /home/server02/public_html, but that’s likely to cause problems later on, because virtualmin then still writes its apache configuration into the virtual host, which will still get ignored in favor for the default/global config.

IMHO it would be cleanest and easiest way to use a subdomain / multiple subdomains that do not name-clash with the server hostname for the http(s)-based-services you want to set up. This likely avoids the problems you encountered and also allows you to use the script installers.

I am now on the road to set up the letsencrypt thing you pointed out in the other post.

But i admit, i am still a little stuck.

Using Ubuntu 14.04 i have Apache 2.4.7; so i use the first part of th apache directives, correct? I’ve put them in conf-available letsencrypt.conf and symlinked it in conf-enabled too.

I see two options now:

  1. Create one cert for all domains in Webmin and setting the root dir to /var/www/html.
  2. Create them with this: /letsencrypt-auto certonly --renew-by-default -c /etc/letsencrypt/cli.ini
    and putting all domains whether www. or not into the cli.ini file. If the renew command does not find certs, will it create this right away? Then i could cron that command every 60 days or so, and it would initially create the certs i need

Since my server will get more virtual hosts over time, i am wondering whether i can get virtualmin to use the cert directories automatically instead having to change each .conf file.

BTW, how to get the server02 certs into postfix, webmin, dovecot and have them updated automatically as well? You said in the other post, not to copy that cert into webmin. I’d also like to use PFS; but there are different ways to get it done, i have to check the best way to implement this too :slight_smile:

I am sorry, if this sounds dumb :slight_smile: but i try to get on top to this.

Thank you very much, i am farther down the road now than two days ago.

I am sorry, if this sounds dumb :slight_smile: but i try to get on top to this.

No problem, explaining things always helps both parties to understand them better. Your option 2 actually looks quite nice, so lets go with that :wink:

First: I think you put the apache directives into the wrong file. AFAIK conf-available is just the source for symlinks in conf-enabled and isn’t sourced by default and actually is meant to be used for virtual hosts. Global configurations should go into httpd.conf or into a conf/ or conf.d/ subdirectory. I’m not sure things work the way you did it, because virtual hosts that alphabetically come before ‘letsencrypt’ may not be affected by the later sourced global directives. In any way, I think it’s cleaner to put things into the above mentioned one of the above mentioned files or directories.

Anyway, once you have that and restarted apache, put a test-file in /var/www/html/.well-known/acme-challenge/ and try to access it from different domains. Then you’ll see whether or not the rewrite directive works.

Now, try to run the command as shown in your second option. Make sure that you also set the webroot-path in the cli.ini to /var/www/html. Also, make sure that the first domain listed is your server hostname, as I think that will be the directory name in /etc/letsencrypt/live. If that works, there should be privkey.pem, cert.pem, chain.pem and fullchain.pem in the respective directory.

So, how to get applications use those files:

  • For virtualmin it looks like this can’t be set in the server templates, and I’m not sure if virtualmin will overwrite this, but you should be able to globally set the default SSLCertificateFile, SSLCertificateChainFile and SSLCertificateKeyFile. grep for them in the apache config directory to find the place where they are documented. They first two should point to the fullchain.pem, the last one to the privkey.pem (Reasoning here).
  • For postfix and dovecot grep for things like ssl, tls, cert or similar in the config directories. You should find what you are looking for there. Always, when they have a _cert directive link them to the fullchain.pem, as otherwise they won’t send the intermediary certificate and you’ll get TLS warnings in the clients. Of course this can also be done in webmin, but this way is always good to learn things a bit better (as there’s often very good documentation in those configuration files).
  • For the Webmin and Usermin servers it’s really easiest to do that in Webmin->Webmin->{Webmin, Usermin} Configuration.

To set up PFS I’m gonna direct you to some very good sources, because I am in a hurry unfortunately:

(If you also want ECDSA, here is the most up-to-date information source for that, but first you should get RSA running :slight_smile:

i’ve been two days on the road, so i can tackle this again.a
i tried various ways to include this:

# Globally redirect ACME challenges to /var/www/html # simpleHttp challenge by default uses HTTP Redirect /.well-known/acme-challenge/ http://%{SERVER_NAME}/.well-known/acme-challenge/ # If simpleHttp is used with TLS the above may not work. # In that case we have to do something like this: # (doesn't work for me right now; if someone gets this working please respond) # # Redirect /.well-known/acme-challenge/ http://%{SERVER_NAME}/.well-known/acme-challenge/ # # # Redirect /.well-known/acme-challenge/ https://%{SERVER_NAME}/.well-known/acme-challenge/ #

into apache2 :slight_smile: Whether i put it into a conf file in a conf directory or whether i put it in the apache.conf, it won’t redirect. Of course it will work with the server’s own domain name, but not with the other virtual hosts i have running. Perhaps it is my apache 2.4.7, whichis the latest version for Ubuntu 14.04 as of today?

I will dig more on that, and give the other option a try:

# Global Rewrite Rules for ACME challenges #RewriteEngine on # New in Apache 2.4.8: gets rid of the explicit `RewriteOptions inhert` in every vhost # NB: With the right InheritOptions this can also be used to have a global configuration # that can be overridden in selected virtual hosts. #RewriteOptions InheritDown # HTTP #RewriteCond %{SERVER_PORT} !^443$ [OR] #RewriteCond %{HTTPS} !=on #RewriteCond %{REQUEST_URI} ^/.well-known/acme-challenge/.* #RewriteRule ^(.*) http://%{SERVER_NAME}:80/ [R] # HTTPS #RewriteCond %{SERVER_PORT} ^443$ [OR] #RewriteCond %{HTTPS} =on #RewriteCond %{REQUEST_URI} ^/.well-known/acme-challenge/.* #RewriteRule ^(.*) https://%{SERVER_NAME}:443/ [R]

Thanks and best

I just checked the Ubuntu 14.04 docs and things should work if placed in apache.conf.
Check if mod_alias is enabled with apache2ctl -M and check the configuration with apache2ctl configtest.
Did you replace %{SERVER_NAME} with the servers own domain name? My original post may have been a bit unclear about this.
If nothing works, try something like this in apache.conf to see if the redirect directive is actually getting applied:

Redirect /.well-known/acme-challenge/

So i edited here:

and here

Redirect /.well-known/acme-challenge/ http://%{SERVER_NAME}/.well-known/acme-challenge/


<If “%{HTTP_HOST} != ‘%{}’”>


Redirect /.well-known/acme-challenge/

service apache2 restart

and if i enter it will show in the browser the index.html i put in there. The link in the browser changes to

So i assume, this should work now.

Next thing is to create the cert. And then do the following:

change virtual hosts conf file for new location of certs and change dovecot and postfix confs to find the correct cert folder.

Or do i miss something?

Thanks again.

No, looks good. Create the cert with letsencrypt-auto or via webmin, whatever you feel more comfortable with.

I did it. (lol)
I ran that option 2:

/letsencrypt-auto certonly --renew-by-default -c /etc/letsencrypt/cli.ini

And experienced some confusion in the /etc/letsencrypt/live directory. Since i had created one cert before for another subdomain, it created the new SAN cert not with servername, although i had this first in my domain list, but with the existing subdomain. So i cleared all folders by removing all content in all folders and ran that command again. And guess what? it worked. Now the live folder contains folder with all other files.

Then i moved on to change virtualmins virtual host config so it can use the new cert.

You wrote

but you should be able to globally set the default SSLCertificateFile, SSLCertificateChainFile and SSLCertificateKeyFile.

Instead setting it globally i did it in the virtualhost conf file.

i found out that the options are this:

SSLCertificateFile /etc/letsencrypt/live/ SSLCertificateKeyFile /etc/letsencrypt/live/ SSLCACertificateFile /etc/letsencrypt/live/ Since i am still running apache 2.4.7, i think the SSLCertificateChainFile setting you mentioned is here the SSLCACertificateFile, so i set it like above.


service apache2 restart ....

Next i opened the domain where i changed the config file and it showed the green lock in front and opening the cert it says:

DSA Root Level 3 has identified this site as:
This connection to the server is encrypted.

Show certificate yields this:

issued for:

issued by Let’s Encdrypt Authority X3

So as far as i came here, i think this should work.

Next is to put this certs in place with Postfix, Dovecot and Virtualmin.

I put it within Webminconfig, which was working, when i pointed it to letsencrypt folder. If i view the cert in Webmin it shows me the additional domains, so that is working too.

In Virtualmin i have the option to copy certs into dovecot, proftpd and postfix, but i haven’t found something within webmin for the webmin cert yet.

If i cant find anything i will need to do it manually.

But didn’t think i would get so far.
Thanks again.


PS: If i am through with everything i will put together an according guide for this, because it is hard to figure everything out and work your way. But it is fun and you learn a lot, as you pointed out above.

Next one:

I found the according config in webmin for dovecot and set it up like this:

SSL certificate file: /etc/letsencrypt/live/ SSL private key file: /etc/letsencrypt/live/ SSL CA certificate file: /etc/letsencrypt/live/

Looks logical for me. More interesting are Postfix settings:

TLS certificate file: /etc/letsencrypt/live/ TLS private key file: /etc/letsencrypt/live/ TLS CA certificate file: /etc/letsencrypt/live/

But there is more:

Standardsetting after using are:

Require SASL SMTP authentication: Yes Enabel TLS encryption: Yes Send outgoing mail via host Option 1: Deilver directly Option 2: (emptyfield for manual config). Selected is option 2 without any input Use SASL SMTP authenthication: No SMTP login to outgoing mailhost: None needed

Shouldnt those options being set like:

Require SASL SMTP authentication: Yes Enabel TLS encryption: Yes Send outgoing mail via host:Ö Deilver directly Use SASL SMTP authenthication: YES SMTP login to outgoing mailhost: None needed

It doesn’t sound very logical for me, having

Require SASL SMTP authentication: yes

and then

Use SASL SMTP authentication: No

I am also wondering why the option for sending outgoing mail via host is not being set to deliver directly instead pointing to a config field, which is empty.

So how should i proceed here? I also remember, that virtualmin had a feature about copying a cert into ProFTPd, but in Webmin there doesn’t seem to be an option for this. But if there is an option, i haven’t found it, so i will dig within its config files. Given that ProFTPd is also not very reliable running on Ubuntu 14.04, i might break everything. But i will find out …

Thank you very much.

PS: When my cronjob will renew certs, they will be found afterwards in correct place, not in those special subfolder config, webmin/virtualmin is using, correct?

  1. Your dovecot/postfix configurations won’t work. You have to set the ‘certificate file’ to fullchain.pem. The SSL/TLS CA file option in dovecot and postfix are for client certificate validation. You usually don’t need to set those options as long as you are not using client certificates for authentication.

  2. SASL SMTP authentication isn’t enabled by default because it isn’t used by Virtualmin. Every user in Virtualmin has his own unix account.

  3. Yes, normally, unless your using an internal to outbound mail gateway, this should be set to ‘deliver directly’, but it looks like an empty field and the first option are semantically equivalent.

  4. I haven’t set up ProFTP here either, because it’s not working in CentOS 7 either… :confused:

  5. Assuming the correct place is /etc/letsencrypt/live, then yes. But any copy that is placed elsewhere will then be outdated. That’s why I am so keen to not use copies at all, but just configure everything correctly and point everything there. Nevertheless, it’s a good practice to test your cron-script to make sure it actually renews the certificate and doesn’t place the new one in /etc/letsencrypt/live/ or so. From what I’m remembering from the documentation this should only happen if you remove domains from the .ini-file you are using, because it only renews a certificate in place, if all domains from the previous certificate are also in the newly requested one [Source]. I should probably check the letsencrypt issues if there’s something planned to make this easier to handle…

I will deselct the option with the CA cert file in dovecut / postfix.

Before i saw your post i made a new emailaccount and got Outlook to set SSL always to automatic and checked lateron the logs:


Obsolete setting in /etc/dovecot/dovecot.conf:103: ssl_ca_file has been replaced by ssl_ca = <file

I’ve got to check this out.

Any chance that there is a log file where i can check, whether Mailtransfer runs via SSL with Dovecot and TLS with Postfix (that are the settings i had to use in outlook, since Postfix doesn’t seem to use SSL).

I also made it PCI Compliant as of here.

So on my roadmap is now proftpd and PFS :slight_smile:

Thanks and best

I’ve been eyeing those “copy to Webmin/Usermin/Dovecot/Postfix/ProFTPD” buttons, but confess I’m afraid to click one. I don’t know what changes they’ll make to my server. I’d hate to try turning something on and find that something breaks. I’d be more confident if these were check-boxes as in “Edit Virtual Server” so that I can reverse the cert support instead of scramble to clean things up manually. :slight_smile:

@just_me: I don’t know where Ubuntu stores the mail logs, but for me it’s /var/log/maillog.
I listed some web services for client side testing in a previous post. There’s also a very good command line tool that can pretty much test everything:

@AustintX: Excerpts from my configuration (CentOS 7 based), if you want to have a bit more control over what actually happens without having to read the perl scripts in /usr/libexec/webmin:

/etc/webmim/miniserv.conf and /etc/usermin/miniserv.conf:



smtpd_tls_cert_file = /etc/letsencrypt/live/
smtpd_tls_key_file = /etc/letsencrypt/live/


 ssl_cert = </etc/letsencrypt/live/
 ssl_key = </etc/letsencrypt/live/

My ProFTPD configuration is in /etc/proftpd.conf. The settings should be TLSRSACertificateFile and TLSRSACertificateKeyFile, but I’m not using ProFTPD at the moment and am not quite sure whether one has to pass the cert.pem or fullchain.pem to TLSRSACertificateFile.

For everything else like SSL/TLS versions, ciphers, cipher suite ordering, DHE parameters (or not using DHE), etc the reading recommendations from my earlier post still stand. These things have to be configured according to clientele or company policy and anything written here would only become outdated over time.

OH and it should go without saying, after all your configurations stop and start all services dependent upon your new certs to make sure they stick like glue. This will point you to any errors you made in configuring them.

You can have letsencrypt in opt but those are only scripts and binaries. your keys are stored in etc/letsencrypt/live/yourdomainname subdirectories

In the live directory you should have a subdirectory for each domain url you want a cert for with a cert and key in it.

I use a crontab job (one for each virtual domain) to obtain the .pem files, update them if needed, and copy them them to the domains home directoty folder for me. it copies them to a location in the users home directory that is known i.e. /home/mydomainname/ssl_certificates. Note: crontab should be pointed to the directory that you installed the scripts and binaries into, /opt/letsencrypt in your case to launch the certbot.

Then, after obtaining, updating and copying the certs with whatever mechanism you choose to do so, AND while managing one of your virtual domains in virtualmin, go to the “manage ssl configuration” area of “server configuration” point the virtual domain to look for its keys in the /home/domainname/ssl_sertificates that have been copied there. Do this for each domain you want to use ssl with. You of course have enabled the ssl website option in the virtual domain enabled Options settings.

To eleminate the dovecot error just hit the copy to dovecot button but only do this for the main domain you set virtualmin up with. It’s the fqdn you see when you run hostname. don’t use the servername anywhere just the domain. I am actually here in this forum for that very reason … how to set up dovecot to look for a cert for each virtualdomain not just one…

It just works and you can set the job up to take place monthly or whatever your scenario needs.

I can set this up manually and have many time in the past but virtualmin adds a twist to your configuration files and sometime they are not what you think they should be. I try and use virtualmin automation as much as I can but sometime you have to think a step ahead of it. I don’t like "nano"ing config files to solve problems, i just look at them to see the path that virualmin has taken for authentication and things like that and work with them.

Hope I helped you.