Search code examples
phptypo3cloudflare

TYPO3 too many redirects


My environment is the following:

Cloudflare (HTTPS) -> AWS ALB (HTTPS) -> AWS EC2 (HTTP) (nginx, php-fpm, typo3)

I am using the Cloudflare Full (strict) SSL mode.

So there is double SSL termination, once on Cloudflare and another on the AWS load balancer. The TYPO3 application is receiving requests on HTTP.

The nginx configuration I use is from the official TYPO3 documentation:

Excerpt:

...

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location = /typo3 {
    rewrite ^ /typo3/;
}

location /typo3/ {
    absolute_redirect off;
    try_files $uri /typo3/index.php$is_args$args;
}

location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    fastcgi_buffer_size 32k;
    fastcgi_buffers 8 16k;
    fastcgi_connect_timeout 240s;
    fastcgi_read_timeout 240s;
    fastcgi_send_timeout 240s;

    # this is the PHP-FPM upstream - see also: https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/#connecting-nginx-to-php-fpm
    fastcgi_pass         php-fpm:9000;
    fastcgi_index        index.php;
    include              fastcgi.conf;
}

When I access https://<MY_DOMAIN>.com/typo3/ I get an ERR_TOO_MANY_REDIRECTS error. My index.php in the typo3/ folder is standard, nothing unusual about it. It should be loading the TYPO3 application.

<?php
call_user_func(static function () {
    $classLoader = require dirname(dirname(__DIR__)).'/vendor/autoload.php';
    \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(1, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE);
    \TYPO3\CMS\Core\Core\Bootstrap::init($classLoader)->get(\TYPO3\CMS\Backend\Http\Application::class)->run();
});

On another TYPO3 website I have, where I don't use Cloudflare + load balancer, where the SSL is terminated on the server itself I don't have this issue.

There is nothing in the logs to indicate where the issue could be. I even enabled debug logging in nginx. TYPO3 receives requests on HTTP. My assumption is that TYPO3 itself is redirecting to HTTPS which causes a redirect loop, but I am not sure.


Solution

  • There is a ForcedHttpsBackendRedirector middleware in TYPO3 that redirects from http:// to https:// if the lockSSL configuration option is not false or zero. Try to set that option to false in the TYPO3 configuration.