Moodle 3.7 & Apache Reverse Proxy ERR_TOO_MANY_REDIRECTS – Troubleshooting

apache-2.4Apache2moodle;reverse-proxy

Moodle 3.7 Apache with reverse proxy results ERR_TOO_MANY_REDIRECTS.

I have an SSL site with following vhosts file on Frontend server:

<VirtualHost *:80>
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>     


<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName moodle.site.com:443

SSLEngine on
SecAuditEngine On
RewriteEngine On

    ProxyPreserveHost On
    ProxyPass / http://101.102.103.104:80/
    ProxyPassReverse / http://101.102.103.104:80/

</VirtualHost>                                  
</IfModule>

I also redirect all 80 port requests to SSL port.

The command

curl -I https://moodle.site.com/

results:

HTTP/1.1 303 See Other
Date: Fri, 09 Aug 2019 19:13:33 GMT
Server: Apache/2.4.38 (Debian)
Strict-Transport-Security: max-age=15768000; includeSubDomains
Location: https://moodle.site.com
Content-Language: en
Content-Type: text/html; charset=UTF-8

On Backend server in Moodle config.php I have:

$CFG->wwwroot   = 'https://moodle.site.com';
$CFG->reverseproxy = true;
$CFG->sslproxy  = 1;

Any idea why I get "ERR_TOO_MANY_REDIRECTS" error in Google Chrome, when I try to open https://moodle.site.com URL?

EDIT1:

101.102.103.104 is the IP address of the Moodle backend server.
The frontend server has moodle.site.com subdomain name, which resolves to 1.2.3.4.
The user enters the moodle.site.com URL, which should reverse proxy content from Moodle backend server from 101.102.103.104 IP address.

Best Answer

I have no access to web server config so I have to find this workaround. File lib/setuplib.php, line 900 in my case, Moodle comment of this: $CFG->sslproxy specifies if external SSL appliance is used (That is, the Moodle server uses http, with an external box translating everything to https).

Change

  if (empty($CFG->sslproxy))

for

  if (!empty($CFG->sslproxy))

That was all needed to begin installation normally. (after two hours of debugging inserting die()'s everywhere)