diff --git a/config/config.sample.php b/config/config.sample.php
index 3d0a70db1d81c13a804a4aeb62b541fb06f5c35b..0ef90a0469973645972db0faa658282308f7f535 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -30,6 +30,12 @@ $CONFIG = array(
 /* Force use of HTTPS connection (true = use HTTPS) */
 "forcessl" => false,
 
+/* The automatic hostname detection of ownCloud can fail in certain reverse proxy situations. This option allows to manually override the automatic detection. You can also add a port. For example "www.example.com:88" */
+"overwritehost" => "",
+
+/* The automatic protocol detection of ownCloud can fail in certain reverse proxy situations. This option allows to manually override the protocol detection. For example "https" */
+"overwriteprotocol" => "",
+
 /* Enhanced auth forces users to enter their password again when performing potential sensitive actions like creating or deleting users */
 "enhancedauth" => true,
 
diff --git a/lib/request.php b/lib/request.php
old mode 100644
new mode 100755
index 287d20d1a5dbe550a0f3096c7e7499630de7c7e3..c975c84a7117349a9af951ca9a6a5b2dbbb82de4
--- a/lib/request.php
+++ b/lib/request.php
@@ -18,6 +18,9 @@ class OC_Request {
 		if(OC::$CLI) {
 			return 'localhost';
 		}
+		if(OC_Config::getValue('overwritehost', '')<>''){
+			return OC_Config::getValue('overwritehost'); 
+		}
 		if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
 			if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) {
 				$host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST'])));
@@ -40,6 +43,9 @@ class OC_Request {
 	* Returns the server protocol. It respects reverse proxy servers and load balancers
 	*/
 	public static function serverProtocol() {
+		if(OC_Config::getValue('overwriteprotocol', '')<>''){
+			return OC_Config::getValue('overwriteprotocol'); 
+		}
 		if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
 			$proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
 		}else{
diff --git a/ocs/providers.php b/ocs/providers.php
index 43c9dc2aa42b4d1e7cd843e09cd6dd5d38d235d2..0c7cbaeff081c69d0c1d1c8942435a0d30d255d5 100644
--- a/ocs/providers.php
+++ b/ocs/providers.php
@@ -23,7 +23,7 @@
 
 require_once '../lib/base.php';
 
-$url='http://'.substr(OCP\Util::getServerHost().$_SERVER['REQUEST_URI'], 0, -17).'ocs/v1.php/';
+$url=OCP\Util::getServerProtocol().'://'.substr(OCP\Util::getServerHost().$_SERVER['REQUEST_URI'], 0, -17).'ocs/v1.php/';
 
 echo('
 <providers>