moodlehq / moodle-docker

A docker environment for moodle developers
GNU General Public License v3.0
376 stars 245 forks source link

Broken Behind Proxy #193

Closed jvanalst closed 2 years ago

jvanalst commented 2 years ago

Hi,

Because of our local network security I can't access the container directly, and have to run it through a Proxy for team testing/development (only port 80/443 are available to the world).

I tried running it behind mod_proxy:

        ProxyPreserveHost on
        ProxyPass / http://localhost:8100/
        ProxyPassReverse / http://localhost:8100/
        RequestHeader set X-Forwarded-Proto "https"
        RequestHeader set X-Forwarded-Port "443"

The problem is Moodle then tries to redirect to localhost:8100 because of the ProxyPreserveHost setting. If I leave the ProxyPreserveHost off, then Moodle can't link correctly to itself (e.g. it tries to access .css files through localhost:8100 instead of moodle.mysite.com).

I also tried using:

export MOODLE_DOCKER_WEB_HOST=moodle.mysite.com

But that just makes Moodle redirect to moodle.mysite.com:8100 instead of localhost:8100.

I found some proxy settings in the Moodle config table, but I'm having trouble finding documentation for them:

| 362 | getremoteaddrconf   | 3                    |
| 363 | reverseproxyignore  |                      |
| 364 | proxyhost           |                      |
| 365 | proxyport           | 0                    |
| 366 | proxytype           | HTTP                 |
| 367 | proxyuser           |                      |
| 368 | proxypassword       |                      |
| 369 | proxybypass         | localhost, 127.0.0.1 |

Any suggestions?

jvanalst commented 2 years ago

Turns out I had to modify the provided config.php file manually. I added the following lines to the end of the file:

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

It'd be nice though it there was a MOODLE_DOCKER_PROXY_HOST/_PORT so that the default could sort this stuff automatically instead of having to manually set it and know what I'm doing.

See also: Reverse Proxy Frontend

stronk7 commented 2 years ago

Thanks, @jvanalst !

Yeah, some specific environments do require some specific configurations. But we cannot create new env variables for every possible Moodle setting, so the approach is to make it to work ok for 95% of people and make specific environments to perform the configuration "manually".

Nice you have "documented" (in this issue), both the problem and the solution so, anybody facing similar problems, will read this and find how to make moodle-docker to work behind proxy.

Ciao :-)