Index: core/kernel/startup.php
===================================================================
--- core/kernel/startup.php
+++ core/kernel/startup.php
@@ -39,8 +39,15 @@
 	define('ADMIN_DIRECTORY', $vars['AdminDirectory']);
 	define('ADMIN_PRESETS_DIRECTORY', $vars['AdminPresetsDirectory']);
 
-	$https_mark = getArrayValue($_SERVER, 'HTTPS');
-	define('PROTOCOL', ($https_mark == 'on') || ($https_mark == '1') ? 'https://' : 'http://');
+	if ( array_key_exists('HTTP_NGINX_PROTO', $_SERVER) ) {
+		define('NGINX_PROTOCOL_OVERRIDE', true);
+		define('PROTOCOL', $_SERVER['HTTP_NGINX_PROTO'] === 'https' ? 'https://' : 'http://');
+	}
+	else {
+		define('NGINX_PROTOCOL_OVERRIDE', false);
+		$https_mark = getArrayValue($_SERVER, 'HTTPS');
+		define('PROTOCOL', ($https_mark == 'on') || ($https_mark == '1') ? 'https://' : 'http://');
+	}
 
 	if ( isset($_SERVER['HTTP_HOST']) ) {
 		// accessed from browser
@@ -54,14 +61,16 @@
 
 	$port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : false;
 
-	if ($port) {
-		if ( (PROTOCOL == 'http://' && $port != '80') || (PROTOCOL == 'https://' && $port != '443') ) {
-		// if non-standard port is used, then define it
-        	define('PORT', $port);
+	if ( $port ) {
+		if ( !NGINX_PROTOCOL_OVERRIDE
+			&& ((PROTOCOL == 'http://' && $port != '80') || (PROTOCOL == 'https://' && $port != '443'))
+		) {
+			// If non-standard port is used, then define it.
+			define('PORT', $port);
 		}
 
 		$http_host = preg_replace('/:' . $port . '$/', '', $http_host);
-    }
+	}
 
 	define('SERVER_NAME', $http_host);