[Howto] Individual themes per domain

Hi, could you please let me know what I should type in the ubuntu 20.04 terminal in order to edit and add trusted ip address? Should I use 0.0.0.0. in order to let the vm to be reachle from anywhere? Many thanks for your support

You don’t need to add trusted IP addresses at all, if you’re gonna access your Nextcloud via one or multiple domain names. Just add the FQDNs to the config.php, like this…

  'trusted_domains' =>
  array (
    0 => 'cloud.domain.com',
    1 => 'cloud.otherdomain.com',
  ),

Of course you also have to configure your web server or proxy accordingly.

If you have any more questions, please open a new thread and describe in more detail how your current setup looks like and what you are trying to achieve.

hi
I think i’ve read that the Theming module in NC will prevent the domain.config.php to be applied.
How are we going to do then with NC25, caus it seems that Theming can’t be disabled in this version of NC …?

I’ve spent some time with this topic and managed to kinda make it work for me.
First: domain.config.php still works, even while the theming app cannot be disabled.

I started with replacing strings in the generated output via JavaScript injection, which works to an extent, but only for the frontend. Nextcloud is still serving the original theme data.

This method also does not offer itself to alter the meta tags.

Then I looked into injecting custom CSS via the native method, which allows a lot of restyling and even replacing strings with some “hacks”. But this, too, did not help the issue that any non Browser interaction still receives the old theme data, making things confusing and also was complicated to catch based on the domain accessing Nextcloud.

What I ended up with, for now:

  • Overwrite CSS via CSS variables assigned to server.css and guest.css the legacy /themes/domain.tld/core/css folder
  • Not serving a defaults.php, since most of its variables are ignored nowadays
  • Regular expressions to replace generated HTML via my reverse proxy based on the domain accessing nextcloud

I’m using caddy v2 as a reverse proxy. I generated the following snippet:

(nc_replace) {
        replace stream {
                arglist {args.0},{args.1},{args.2},{args.3},{args.4},{args.5}
                re "defaultdomain|[^@]defaultdomain.tld" "{args.0}"
                re "(?mi)(.*?them.{0,100})(#.{6})([^a-zA-Z0-9].*)" "${1}{args.6}${3}"
                re "(?mi)(.*?them.{0,170})(#.{6})([^a-zA-Z0-9].*)" "${1}{args.6}${3}"
                re "(?m)(name=\"theme-color\" content=\")(.+?)(\"\>)" "${1}{args.3}${3}"
                re "(?m)(meta property=\"og:title\" content=\")(.+?)(\"\>)" "${1}{args.0}${3}"
                re "(\<title\>\s*Login\s*–\s*)(.+?)(\s*\<\/title\>)" "${1}{args.0}${3}"
                re "(?m)(meta property=\"og:description\" content=\")(.+?)(\"/>)" "${1}{args.1}${3}"
                re "(?m)(meta property=\"og:image\" content=\")(.+?)(\"/>)" "${1}https://{args.7}/themes/{args.0}/core/img/{args.5}${3}"
                re "(?m)(\"https:\/\/)(.+?)(\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"entity-name\">)(.+?)(\<\/a\>)(.+?)(\<\/p\>)" "${1}{args.4}${3}{args.0}${5} - {args.>
                re "(?m)\/apps\/theming\/image\/logo\?useSvg=(.+?)\"" "{args.7}"
        }
}

I call this snippet via the help of a named matcher and matched handler:
@domain.tld host cloud.domain.tld

        handle @domain.tld {
                import nc_reverse_proxy
                import nc_replace "domain.tld" "slogan" "sitename" "#<theme color in hex>" "cloud.domain.tld" "favicon.webp" "#<accent color in hex>" "cloud.domain.tld" '/themes/domain.tld/core/img/logo.webp"'
        }

These replacements alone help to create correct metadata and have the page completely render differently for different domains – so far the only thing I cannot catch is the template of the emails – they are still based on the default theme.

Additional CSS fun is being had via the custom, domain-based CSS files following the theme routing mentioned in this threat.

Can NextCloud 27.0.2 use this method anymore?

if (isset($_SERVER['HTTP_HOST'])) {
    switch ($_SERVER['HTTP_HOST']) {
        # Server called with cloud.domain1.com
        case 'domain1.de':
            $CONFIG['mail_from_address'] = '*****';
            $CONFIG['mail_domain'] = 'domain1.de';
            $CONFIG['mail_smtpname'] = '******';
            $CONFIG['mail_smtppassword'] = '******';
            break;
        case 'domain2.de':
            $CONFIG['mail_from_address'] = '*****';
            $CONFIG['mail_domain'] = 'domain2.de';
            $CONFIG['mail_smtpname'] = '******';
            $CONFIG['mail_smtppassword'] = '******';
            break;
        # and so on for other domains
    }
}

you can use the same code, just paste it directly into config.php and then change the permissions on the read-only file ( ‘config_is_read_only’ => true) so you don’t overwrite it with the interface

Yes it can, I already tested.