HTTPS Links behind AWS Load Balancer I really tried many Solutions to get my site work on Amazon AWS. There is only one last thing i can not solve. Some of my links are still "http://"-links and i dont know how to get them right.

My Setup:


Drupal 8.6.10 running on an EC2-Instance managed via Beanstalk
the Load-Balancer is managing the access and has two open ports (http/80 and https/443) directing to the ec2-instance via http (port 80)
the ssl-certificate is configured
my domain has the correct dns-config directing to xxx.eu-central-1.elasticbeanstalk.com 
settings.php includes the following lines 


     $settings['reverse_proxy'] = TRUE;
     $settings['reverse_proxy_addresses'] = array($_SERVER['PROXY_ADDRESS']);
     $settings['reverse_proxy_proto_header'] = 'https';
     conf['https'] = TRUE;
     $_SERVER['HTTPS']='on';



$_SERVER['PROXY_ADDRESS'] is assgned to 'xxx.eu-central-1.elasticbeanstalk.com' by beanstalk
.htaccess includes the following lines:


     RewriteCond %{HTTPS} off
     RewriteCond %{HTTP:X-Forwarded-Proto} !https
     RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


The affected places are:


in a twig: url('') 
in a php-file: fileentities->url(); 


All other links are nicely rendered as 'https'-links. I would be really thankfull for any advice you could give me. 

Best Regards,

FirstSanny
Try the folling setup:

In settings.php:

if (PHP_SAPI !== 'cli' &amp;&amp; !empty($_SERVER['REVERSE_PROXY_ADDRESSES'])) {

  $settings['reverse_proxy'] = TRUE;
  $settings['reverse_proxy_addresses'] = array($_SERVER['REVERSE_PROXY_ADDRESSES']);

  $settings['reverse_proxy_header'] = 'X-Forwarded-For';
  $settings['reverse_proxy_proto_header'] = 'X_Forwarded-Proto';
  $settings['reverse_proxy_port_header'] = 'X-Forwarded-Port';  

  // HTTPS behind reverse-proxy
  if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &amp;&amp; $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
    $_SERVER['HTTPS'] = 'on';
    // This is hardcoded because there is no header specifying the original port.
    $_SERVER['SERVER_PORT'] = 443;
  }
}


In your .htaccess:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteCond %{HTTP_HOST} !^(.*\.)*localhost(.*)$ [NC]
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]


(change $_SERVER['REVERSE_PROXY_ADDRESSES'] to $_SERVER['PROXY_ADDRESS'] for your setup)

This worked fine for me.