Moodle with NGINX Layer 7 loadbalancing

Re: Moodle with NGINX Layer 7 loadbalancing

by Matt T -
Number of replies: 0
There's really two stages of this process. First, changing the URL configuration in Moodle. Secondly, configuring the reverse proxy, and configuring Moodle to work properly with it.

1. Take a full backup of your nginx configuration file(s), code directory, database and moodledata folder. Don't proceed until this is done.
2. Configure nginx to proxy /moodle to your Moodle application server. Consult the nginx manual. In essence you will need to use the proxy_pass directive within a location block.
3. Change the wwwroot setting in config.php. $CFG->wwwroot needs to be changed from "https://www.example.com" to "https://www.example.com/moodle".
4. You should run the 'search and replace' tool to change any links on the site accordingly. See here: https://docs.moodle.org/310/en/Search_and_replace_tool
5. Check if the site works. If not, sometimes for Moodle to work properly with a reverse proxy, you need to edit config.php and set $CFG->reverseproxy = true;

If you intend to run multiple Moodle application servers and load balance them (which isn't clear based on your post), there are further advanced configuration steps. It may well be that you only intend to have one Moodle application server, and the purpose of the load balancer is to balance load between different web applications. If that's the case the above steps will suffice. If you wish to load balance Moodle, you need to run a shared database, shared cache, shared dataroot (moodledata) folder, and have a way of orchestrating code updates between the servers.
Average of ratings: Useful (2)