Finally I have been able to fix the problem, I am writing this answer with a bigger level of detail so other people having this problem can follow my answer.
First we need to edit the apache2 config for our site:
In general the apache2 configuration for your specified site can be found at /etc/apache2/sites-enabled
. Depending if you are using http or https you need to edit the right configuration file. Default name for http is 000-default.conf
and for https 000-default-ssl.conf
Add the following lines between the <VirtualHost *:80>....</VirtualHost>
sections.
# MOODLE
ProxyRequests Off
ProxyPreserveHost On
ProxyPass "/" "http://10.10.10.10:81/moodle/"
ProxyPassReverse "/" "http://10.10.10.10:81/moodle/"
Then we need to restart our apache2 webserver, this can be done with the command service apache2 restart
.
Now we also need to edit a few things in our moodle config.php
file. This file can be found at /var/www/html/moodle
on the server with the IP (in this case) 10.10.10.10
if you used the default install location from the moodle guides.
In the config.php
file we append the following lines under the default $CFG
declarations: Please make sure to change all values according to your server setup.
$CFG->wwwroot = 'http://public.domain.com';
$CFG->dirroot = '/var/www/html/moodle';
$CFG->reverseproxy = true;
//$CFG->sslproxy = true; //UNCOMMENT this line if you are using SSL
Attention: If you are not using the root directory at your public webserver, then make sure that you do not use the same directory as moodle is using on the subserver. For example http://public.domain.com/moodle
will fail if moodle is installed on the subserver at /var/html/moodle
since both directories are equal and the proxy loops for some reason. My easy fix for this problem was do just move the moodle installation to /var/html/moodley
including all required changes in the config.php
. This fixes every problem I had.