diff --git a/lib/private/setup.php b/lib/private/setup.php
index a3b46c1eb4f8087843ff1fb3b8c6da0645373465..ede3a452c29003d4958aeeb56df128c32cbf3356 100644
--- a/lib/private/setup.php
+++ b/lib/private/setup.php
@@ -164,7 +164,7 @@ class OC_Setup {
 		    && is_array($options['trusted_domains'])) {
 			$trustedDomains = $options['trusted_domains'];
 		} else {
-			$trustedDomains = [\OCP\Util::getServerHostName()];
+			$trustedDomains = [$request->getInsecureServerHost()];
 		}
 
 		if (OC_Util::runningOnWindows()) {
@@ -187,7 +187,7 @@ class OC_Setup {
 			'secret'			=> $secret,
 			'trusted_domains'	=> $trustedDomains,
 			'datadirectory'		=> $dataDir,
-			'overwrite.cli.url'	=> $request->getServerProtocol() . '://' . $request->getServerHost() . OC::$WEBROOT,
+			'overwrite.cli.url'	=> $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . OC::$WEBROOT,
 			'dbtype'			=> $dbType,
 			'version'			=> implode('.', OC_Util::getVersion()),
 		]);