Magento – Magento wrongly redirects https!

httpsnginxsslvarnish

I have a big problem with one magento installation.
It is a Magento Version 1.8.0.0 running on apache with php5-fpm, a Varnish cache in front and nginx as ssl reverse proxy.

If I open any URL using https, magento redirects to http://shopurl/index.php/
This then redirects to Location:/
I switched Web server rewrites and rediect to startpage off in the settings, no change.
I created a dbg.php

<?php
var_dump($_SERVER);
echo "\n\n\ngetenv('HTTPS'): ";
print_r(getenv('HTTPS'));

The result is: this

You can see, that $_SERVER['HTTPS'] is set.

I don't know where else I can look to find the problem.
For now, I changed the secure url to http://, because users where not able to login or purchase.
But this can't be permanent.

Any Ideas how I can find out what is wrong?

If I activate proxy_redirect http:// $scheme://; in nginx, so it changes redirects to http:// to https://, a redirection loop endlessly redirecting to https://domain/index.php/ is the result.

The apache rewrite log for https://domain/test shows:

127.0.0.1 - - [06/Feb/2014:12:20:14 +0000] [domain/sid#7f6236faac58][rid#7f61439ff0a0/initial] (2) [perdir /var/www/magento/] rewrite 'test' -> 'index.php'

So it seems that the redirect happens inside the magento PHP code…

Best Answer

try to paste this in your index.php

if( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) {
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

or

if( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}

if i understand you right. or your nginx config is wrong.