Setting up correct work of HTTPS in Drupal for case of reverse HTTPS-proxy

I had to configure Drupal, working in the following configuration:

Drupal works on Apache2 webserver with mod_php, which works behind light-weight reverse HTTPS-proxy(e.g. nginx). Apache works with mod_rpaf, and configured correctly to handle requests via reverse proxy. But the problem  is with  connection between apache and proxy. It's over HTTP protocol, that's why  working PHP scripts on server(in our case Drupal) behave so as they work on direct http server. For example Drupal returns pages with incorrect hyperlinks, it's not possible  pass authorization.

After looking on how Drupal core works with protocols, I've found simple solution to make it work correctly in such configuration.

There is just enough add following line in settings.php:

if(
  isset($_SERVER['HTTP_X_FORWARDED_SSL'] )
  && ('on' ==$_SERVER['HTTP_X_FORWARDED_SSL'] )
) {
    $_SERVER['HTTPS'] = 'on';
}

Variable $_SERVER['HTTP_X_FORWARDED_SSL'] of course may depend on  proxy software you use. After adding following lines Drupal startswork with HTTPS without additional modules.