Adding second SSL for second domain

Hi all!

I have a NextCloud server running and it’s working just fine. Now I’ve added second domain to reach this server.

First domain:
Second domain:

Both the domains work, but for the second domain I just can’t seen to figure out how to install a SSL certificate… For the first domain, I simply used certbot and it was set up in minutes. For the second domain I just wanted to do that again but it doesn’t work like that.

When I run the certbot setup I chose to install the SSL on the same virtual host as domain 1.

The error that certbot gives me is this: Could not find a VirtualHost for in the Apache configuration Please create a VirtualHost with a ServerName matching and try again

When I check the folder, the certificate is saved, but not installed/used.

What do I do now? I have a couple of possible solutions but I’m not sure these are correct or logical?

  1. Remove all SSL certificates, rerun certbot and create a single SSL for both domain1 and domain2 (is this even possible?)
  2. Create a VirtualHost for domain2 (Would this not create an entire new NextCloud instance, separate from my already running instance?)

I’d love to hear from you people, I’ve really found the forums to be super helpful so far!

Thanks in advance!

I don’t think you have to delete the existing certificates, but you have to add both names to your VirtualHost (See example below) and run Certbot again. It should then create a certificate that is valid for both domains.

There’s no need to create a separate VirtualHost, as I already implied above, and no, a second VirtualHost wouldn’t create a second Nextcloud instance. Nextcloud is not really multi-tenant capable. And even if it were, Apache can’t change the Nextcloud config on its own and vice versa. However both have of course to be configured accordingly, in order to be able to work together:

Apache VirtualHost example for two domain names:

<VirtualHost *:80>


Nextcloud config.php example:

'trusted_domains' => 
array (
  0 => '',
  1 => '',

Hope that helps…

Thanks for getting back to me so soon!

Where do I add the virtualhost names? Is it located in the Nextcloud config.php file? Both domains are already in the trusted domains list so I think it might just be about adding both domains to the VirtualHost list.

Yes, as in my example. Just add the second domain name as a ServerAlias to your VirtualHost config, on a separate line, and try to run Certbot again. If it still doesn’t work, please post your entire Apache Virtualhost config and the exact command you used to run Certbot.

So unfortunately now the domain that used to work with SSL doesn’t work anymore, and the domain that worked, just wasn’t secure isn’t working…

 <VirtualHost *:80>
#     RewriteEngine On
#     RewriteRule ^(.*)$ https://%{HTTP_HOST} [R=301,L]
RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

<VirtualHost *:443>
    Header add Strict-Transport-Security: "max-age=15552000;includeSubdomains"

#    ServerAdmin
#    ServerName

### SETTINGS ###
    <FilesMatch "\.php$">
        SetHandler "proxy:unix:/run/php/php8.1-fpm.nextcloud.sock|fcgi://localhost"

    # Intermediate configuration
    SSLEngine               on
    SSLCompression          off
    SSLProtocol             -all +TLSv1.2 +TLSv1.3
    SSLCipherSuite          (edited for security)
    SSLHonorCipherOrder     off
    SSLSessionTickets       off
    ServerSignature         off

    # Logs
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Document root folder
    DocumentRoot /var/www/nextcloud

    # The Nextcloud folder
    <Directory /var/www/nextcloud>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    Satisfy Any
    # This is to include all the Nextcloud rules due to that we use PHP-FPM and .htaccess aren't read
    Include /var/www/nextcloud/.htaccess

    # Deny access to your data directory
    <Directory /mnt/ncdata>
    Require all denied

    # Deny access to the Nextcloud config folder
    <Directory /var/www/nextcloud/config/>
    Require all denied

    <IfModule mod_dav.c>
    Dav off

    # The following lines prevent .htaccess and .htpasswd files from being viewed by Web clients.
    <Files ".ht*">
    Require all denied

    SetEnv HOME /var/www/nextcloud
    SetEnv HTTP_HOME /var/www/nextcloud

    # Disable HTTP TRACE method.
    TraceEnable off
    # Disable HTTP TRACK method.
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^TRACK
    RewriteRule .* - [R=405,L]

    # Avoid "Sabre\DAV\Exception\BadRequest: expected filesize XXXX got XXXX"
<IfModule mod_reqtimeout.c>
    RequestReadTimeout body=0

    # Avoid zero byte files (only works in Ubuntu 22.04 -->>)
    SetEnv proxy-sendcl 1

    SSLCertificateFile /etc/letsencrypt/live/
SSLCertificateKeyFile /etc/letsencrypt/live/
Include /etc/letsencrypt/options-ssl-apache.conf

The command used for certbot was

sudo certbot --apache -m -d -d

Later I used the same command for the second SSL, but with the corresponding domains ofcourse.

I would try removing the three lines starting with RewriteCond and then execute Certbot again using the following command:

certbot --apache --redirect -d -d

Hey bb77, thanks, that did work to some extend. Both domains now have an SSL so thats good.
But, something is still wrong, because both URL’s now show me this page… Any idea’s on how/where to fix this?

edit: is this because my trusted domains in the config.php file are “” and “” without the https?

I had another look at the config you posted, and I noticed that the ServerName and Server Alias directives are missing in the second VirualHost

Add the them after <VirtualHost *:443> like this…

<VirtualHost *:443>

…and then restart Apache:

sudo systemctl restart apache2

I did that, but it still show the “Index of /” page for both domains.

Maybe you have not set the correct paths. Read this (Debian) or this (Ubuntu) installation guide (apache2-parts).

Hmm, not sure then. Maybe it is because both VirtualHosts are in the same config file… Usually Certbot automatically creates a second config file for the SSL config and adds redirect directives to the first one…


If your config file is named nextcloud.conf, Certbot will create a second config called nextcloud-le-ssl.conf

This would mean, that you now have two SSL configs for the same Server and Alias Names, but only the one in your first config file contains the additional directives for Nextcloud.

Maybe it would be easier to disable all of the existing configs, and start over with a fresh config.

ls /etc/apache2/sites-available

then disable all the configs:

a2dissite filename.conf

Then create a new simple config file as follows:

nano /etc/apache2/sites-available/nextcloud.conf
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Save the file and exit nano.

Enable the site:

a2ensite nextcloud.conf

Restart Apache and run certbot. Certbot will then create a file called nextcloud-le-ssl.conf, which already contains the directives from the first VirtualHost plus the SSL config. Leave those entries alone and only add the rest of your existing config under <VirtualHost *443> from the old config file to it:

1 Like

Could you elaborate on that? Before I added the SSL at least both domains did work, but only one didn’t have an SSL. Now both have SSL, but don’t work sadly.

Then the path isn’t the issue, if you didn’t change it.

So before I start deleting all config files and starting over, I checked what is in the /etc/apache2/sites-available folder. These are the .conf files in there:

  • 000-default.conf
  • nextcloud_http_domain_self_signed.conf
  • nextcloud_tls_domain_self_signed.conf
  • default-ssl.conf
  • nextcloud_tls_domain_self_signed-le-ssl.conf

Should I check any of these files before starting all over?

You don’t have do delete the files. Just disable them for now, by using the a2dissite command. Once your new config is working, you can delete them.

1 Like

Your previous post helped me tremendously and I have marked it as the solution! Had a little struggle at first I soon realized I edited the wrong file. Thank you so much for this, very helpfull!

1 Like