Nextcloud removes scripts from config.php

Hello!

I use Nextcloud on a TrueNAS server.

I configured access to it via https, and added the following line to config.php

'overwriteprotocol' => 'https'

But I would also like to have access in a fast local network via http. And since Nextcloud in TrueNAS provides only one port that can work only in http or only in https, I added some logic to the config.php file.

if (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], ['example.com', 'www.example.com'])) {
  $CONFIG['overwriteprotocol'] = 'https';
} else {
  $CONFIG['overwriteprotocol'] = 'http';
}

But after rebooting Nextcloud this part of config.php is removed.
I tried setting read-only permissions for the config.php file, but Nextcloud won’t start in that case.

Is there any way to make scripts in config.php persist across reboots, or are there any other ways to provide both http and https access to Nextcloud TrueNAS?

P.S.
I provide the domain and certificate via Nginx-Proxy-Manager.
So, in fact, even without overwriteprotocol, the connection is via https, not http.
However, in this case:

  • Nextcloud complains that the connection is via http in “Administration settings”
  • The login procedure becomes strange. You must first enter your login and password and click login, but then nothing happens. After that, you need to reload the page and only then will the login be completed.
  • The site also takes a long time to open, with overwriteprotocol the site opens in a split second, and without it in 2-4 seconds.

Hello @overgod,

welcome to the Nextcloud community! :handshake:

having 2 different addresses introduces other challenges like non-working sharing URL (which is derived from your address) or requirement to reconfigure your client when moving between networks.

I would rather recommend using splitbraindns 101: Split-Brain DNS (split-horizon) - connection scheme and URL remans the same but network path is optimized in local network so you can utilize full local network speed.

1 Like

overwriteprotocol is only necessary if the reverse proxy isn’t setting X-Forwarded-Proto. If both are present, overwriteprotocol takes precedence. In your case, assuming your reverse proxy is sending the header, you likely don’t want overwriteprotocol set at all.

I believe both NPM and NPMPlus set this header correctly by default.

But after rebooting Nextcloud this part of config.php is removed.

Since you’re using containers, many of these configuration values are overridden by secondary configuration files which, in turn, are populated via environment variables (and, in turn and depending on deployment method, chart values). These take priority over the main config/config.php.

1 Like

This is exactly what I needed, thank you very much!

I have been using TechnitiumDNS for a long time now as my own DNS server for filtering ads/analytics. I just had to add a zone for Nextcloud domain and now everything works great. I didn’t even know I could do this, thanks again!

2 Likes

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.