5

I'm having troubles setting up a moodle instance behind an apache proxy.

Here's my apache front-end that proxies to the running server.

<VirtualHost *:80>
    ServerName public.domain.com

ProxyRequests Off
ProxyPreserveHost On

ProxyPass / http://10.10.10.10:81/moodle/
ProxyPassReverse / http://10.10.10.10:81/moodle/
</VirtualHost>

AND.

$CFG->wwwroot = 'http://public.domain.com';

I install without problems, but when finished the installation I try in browser:

http://public.domain.com

This redirect to: http://public.domain.com/moodle/index.php?sessionstarted=1&lang=en...

Does anyone know what might be happening?

eluish192
  • 145
  • 1
  • 10

2 Answers2

3

The best way to fix this issue is to move the moodle installation on the internal host to the root of web server.

Move your moodle in 10.10.10.10 to be at / and not at /moodle

Note, that if you will use SSL on the external apache (it's suggested) you should also add to your config this line:

$CFG->sslproxy = true;
Yedidia
  • 969
  • 7
  • 12
2

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.

JustRandom
  • 487
  • 1
  • 9
  • 19