Moodle behind a load balancer: sslproxy and reverseproxy explained
A Moodle site moving from one server to several nodes behind a load balancer or TLS terminator needs to tell Moodle how the outside world reaches it. The two settings that do this are sslproxy and reverseproxy in config.php: sslproxy tells Moodle that the browser connection is HTTPS even though Moodle receives plain HTTP from the proxy, and reverseproxy tells Moodle that a proxy sits in front of it and that client address headers can be trusted. Set both only when a proxy is actually present, and set them to match what the proxy really does.
Wrong values produce recognizable symptoms. If sslproxy is missing while the terminator handles TLS, Moodle builds links and redirects with which causes redirect loops or mixed content warnings on pages that load scripts and styles over plain HTTP. If reverseproxy` is enabled on a site with no proxy, a client can set forwarding headers and spoof its address, which matters for IP-restricted quizzes and for logs. If it is missing when a proxy is present, every request appears to come from the load balancer's address. A team needs these settings whenever TLS ends before Moodle. A single server with direct HTTPS on the web server needs neither.
Before changing either value, confirm the header names your load balancer sends, which trusted proxy addresses it uses, and how your web server is configured to pass them through. Test the login page, an asset URL, a quiz with an IP restriction and a log entry from a known client. Note also that from Moodle 5.1 the web server document root must point to the /public directory instead of the main Moodle folder, so the proxy and web server configuration must be reviewed as part of any 5.1 upgrade.
Which proxy settings fit which topology
This table compares three common ways to place Moodle behind a load balancer or TLS terminator, and the proxy settings, forwarded headers and session approach each one needs. Read each row as a question to answer for your own network, then confirm the exact setting names against the Moodle version you run before you change anything.
| Topology | Proxy settings to review | Session approach | When it fits |
|---|---|---|---|
| Single TLS terminator, one web node | Proxy mode on if the browser sees HTTPS but Moodle receives HTTP; confirm the exact keys for your version | Local or shared sessions both work; stickiness is not needed with one node | Small sites where one proxy forwards to one Moodle server |
| TLS terminator, several web nodes | Proxy mode plus forwarded client IP and protocol headers trusted only from the proxy addresses | Shared sessions (for example Redis) or sticky routing; shared sessions are the safer default | Clusters where the proxy terminates TLS and balances plain HTTP to nodes |
| Load balancer passing TLS through to nodes | Usually no TLS proxy mode; each node serves HTTPS and must trust its own certificate chain | Shared sessions are required if requests can land on any node | Designs that keep end-to-end encryption to the application servers |
| Sticky sessions without shared sessions | Same header settings as the chosen topology; stickiness is set on the balancer, not in Moodle | Session files stay on one node; a node failure logs users out | Only as a stopgap; confirm how your balancer handles cookie-based affinity |
| Forwarded client IP for logs and IP-restricted quizzes | Trusted proxy list must include the balancer addresses, or any client can spoof its IP | Not affected by session choice | Any site with IP-restricted quizzes or audit logs that need real client addresses |
| Health checks against Moodle | Check a page that does not require login and does not depend on the proxy headers | Not affected by session choice | Every multi-node design; confirm the path with your Moodle version |
| Wrong proxy settings for the topology | Redirect loops, mixed content warnings, wrong client IPs in logs or login failures | Symptoms often appear only after a second node is added | Common cause of failures during first rollout; test each topology before go-live |
Configure the proxy chain step by step
This sequence takes Moodle from a public URL that is still unconfirmed to a site that generates correct links, keeps users signed in across nodes, and passes the checks that prove the proxy chain is consistent end to end.
Confirm the public URL and wwwroot
Decide the single public address users will type, such as the hostname on the load balancer, and set
$CFG->wwwrootinconfig.phpto exactly that scheme, host and path. Every node must use the same value. Before touching the proxy, run a request against the public hostname and confirm the response comes from Moodle. Done means every node answers to the same wwwroot and no internal hostname appears in generated links.Fix the TLS termination point
Decide where HTTPS ends: at the load balancer, at a web server in front of Moodle, or at each node. Record the decision in the runbook, because it sets which hop carries the original scheme. Confirm the certificate chain is valid on the public name and that traffic between the terminator and the nodes follows the network policy your security team has approved. Done means one documented termination point with a named owner.
Set forwarded headers at the load balancer
Configure the load balancer to add
X-Forwarded-For,X-Forwarded-ProtoandX-Forwarded-Hoston every request it forwards, and to overwrite any values supplied by the client rather than passing them through. Confirm the exact header behavior in your load balancer's documentation, since products differ in how they handle existing headers. Done means a test request to a diagnostic path shows the headers arriving at the web server with the client's real address and the public scheme.Configure the web server to trust the proxy
On each web node, restrict trust to the load balancer's address range, then pass the forwarded values through to PHP. Apache and Nginx each have their own directives for this, so follow the vendor documentation for the version in use. Keep the trusted list narrow so that a client cannot forge its own address. Done means a request sent through the load balancer shows the client address in the web server access log, not the balancer address.
Set Moodle proxy options
In
config.php, set$CFG->sslproxyto true when the browser connects over HTTPS but Moodle receives plain HTTP from the terminator. Set$CFG->reverseproxyto true when Moodle sits behind a proxy that forwards client addresses, and confirm the setting against the Moodle documentation for your version. Set these on every node so behavior matches. Done means the site admin settings page and the login page both show HTTPS links, and no mixed-content warnings appear in the browser console.Point the document root to /public on Moodle 5.1 or later
On Moodle 5.1 or later, the web server document root must point to the new
/publicdirectory rather than the main Moodle folder. If the document root still points to the main folder, the site may show directory listings or errors. Make this change on every node, reload the web server, and confirm that the site loads without directory listings. Done means each node serves the login page from/publicand returns no errors on the admin notifications page.Verify redirects, login, cron and file downloads
Test from two different nodes by signing in through the public URL, then reload the page to confirm the session survives whichever node answers. Trigger a file download and confirm it uses the public HTTPS address. Confirm that cron runs through the intended path and that a quiz restricted to an IP range records the client address correctly in the logs. Trace one request with a browser developer tool or
curl -vto confirm the redirect chain stays on HTTPS. Done means all checks pass and the results are recorded in the change ticket.
Sticky sessions or shared sessions across nodes
A small Moodle cluster with two or three web nodes often works well with sticky sessions. The load balancer pins each browser to one node, so session data can stay in the local file store on that node and no shared session service has to be built or operated. This keeps the first version simple and easy to reason about, and it suits sites where traffic is steady and the user count is moderate. The cost is that a user's session is tied to a node that can fail or be drained for maintenance.
- Session storage: Sessions remain on local disk, so there is nothing extra to run, but every node must have its own writable session path.
- Stickiness rule: Configure cookie-based affinity at the load balancer so the same browser always reaches the same node.
- Failover impact: If a node fails, users on it are signed out or must sign in again, and any unsaved quiz attempt depends on how recently it was saved.
- Maintenance drains: Draining a node means waiting for its sessions to end or accepting that users will be logged out.
- Uneven load: Affinity can concentrate busy users on one node, so watch per-node CPU and PHP worker use.
Before going live, confirm the affinity behavior with a test that signs in, stops one node, and checks what the user sees.
A larger cluster usually moves sessions to a shared store so that any web node can serve any request. This removes the need for affinity to protect session state and makes a node failure or drain far less visible to users. The price is an additional service in the critical path, along with the lock behavior that comes with session storage. The Redis session handler sibling topic covers the settings, hosts, TLS and lock timeouts, so this section focuses on the design choice rather than configuration.
- Failover: Users who land on a surviving node keep their session, which is the main reason to choose shared sessions.
- Lock contention: Moodle locks sessions while a request runs, so a slow page can hold a lock and delay other requests from the same user. Read-only session handling for pages that do not write can reduce this.
- Store availability: The session store becomes a dependency for every logged-in request, so it needs its own high availability design.
- Maintenance drains: Nodes can be removed from the pool without forcing sign-outs, which simplifies patching.
- Operational ownership: Someone must monitor and back up or accept loss of the shared store, which is a recurring cost.
Confirm with your platform team whether the shared store is already run and supported in your environment.
Exam periods change the calculation because a large number of students may start quizzes in a short window. Many institutions use sticky sessions for normal weeks and add capacity or a shared session store for exam weeks, but this only works if the change is planned and tested in advance. The design must consider how many nodes stay in the pool, whether heavy scheduled tasks are paused, and what happens to sessions if a node is lost during a timed attempt. Load testing is the only reliable way to confirm the design for your own user numbers.
- Pre-exam pool size: Decide how many web nodes are active during the window and who can change the pool on the day.
- Affinity under load: Test whether affinity leaves some nodes overloaded while others sit idle, since this is common with a small number of users per node.
- Lock behavior: Check session lock waits during simultaneous quiz starts and saves, because this is where shared sessions are most often stressed.
- Drain freeze: Agree a rule that no node is drained or patched during a timed exam.
- Rollback: Keep a tested way to revert the session method if the shared store degrades mid-exam.
Ask for a load test report and a written exam-day runbook before the first exam window opens.
How a Moodle request travels through the proxy chain
A learner's request starts at the browser, reaches the TLS terminator or load balancer, and is forwarded to a web node running Moodle. Each hop adds forwarded headers such as the protocol and client address, and Moodle only trusts those headers from addresses listed in its reverse proxy settings. The trust boundary sits at that list, so check that it contains only your proxy addresses and nothing a client could reach directly.
Forwarded headers are added at each hop and trusted only from listed proxy addresses.
Health checks and client IP forwarding
Once Moodle sits behind a load balancer or TLS terminator, the proxy becomes the only source of connection details the application sees. Health checks, log entries, IP-restricted quizzes and cookie handling all depend on how that information is passed along and whether Moodle trusts it.
Lightweight health check endpoint
A load balancer that requests a full Moodle page on every probe runs bootstrap, session and database work many times a minute, and a slow database can mark healthy nodes as down. Point the check at a static file or a minimal script that does not start a session, then confirm with your load balancer vendor which status codes and intervals it expects. Test the check during cron and during a deliberate database slowdown so you know which failures it catches.
Client IP in logs
Behind a proxy, the web server sees the proxy's address for every request, so Moodle logs, the standard log report and security audits show one address for all users. Confirm which header your proxy sets, usually X-Forwarded-For, and that the web server is configured to log the forwarded client address. Check a sample of log entries from different networks before you rely on them for incident investigation.
IP-restricted quizzes
Quiz settings that limit access to listed networks compare the requesting address against the allowed range, so a proxy address can either block every student or let anyone through. Confirm that Moodle sees the real client address before you configure the restriction, and test it from inside and outside the permitted network. Record the test results with the quiz configuration so exam staff can repeat them.
Spoofing through untrusted forwarding headers
Any client can send an X-Forwarded-For header, so a web server or application that accepts it from any source lets a user report a chosen address to logs and address checks. Trust forwarding headers only from the proxy addresses you control, and make the proxy overwrite rather than append client-supplied values. Ask your network team to confirm the trusted proxy list and to test a request with a forged header.
Session cookies and HTTPS flags
When TLS ends at the proxy, the request reaching Moodle is plain HTTP, so Moodle may not know the user is on HTTPS and may issue cookies or redirects with the wrong scheme. Confirm that the sslproxy setting matches your termination point and that session cookies carry the secure flag in the browser. Check login, logout and mixed-content warnings after every change to the proxy configuration.
Questions buyers ask about Moodle proxy and load balancer setup
What does a Moodle load balancer and proxy configuration project cost, and what drives the price?
The cost depends on how many layers sit in front of Moodle, how many web nodes run behind them, and how much of the surrounding stack must change at the same time. The main cost components are discovery of the existing network path, configuration of the TLS terminator and load balancer, changes to Moodle settings and web server files, testing of sessions and logins, and documentation for the operations team. Costs rise when the load balancer belongs to another team with its own change process, when several proxies or CDNs sit in the path, or when session storage and file serving also need to change. Costs fall when the network diagram is current and the team can give DeployOpen access to a staging copy. DeployOpen does not publish prices. Ask for a quote built from a written scope that lists each component, who makes each change, and which tests are included.
How long does it take to set sslproxy and reverseproxy correctly?
Duration depends on the environment more than on the Moodle settings themselves. The settings are short to change, but the work around them includes confirming which hop terminates TLS, checking the headers the proxy sends, testing login and redirect behavior, and agreeing a change window with whoever owns the load balancer. Timing also depends on whether a staging environment mirrors production, how many web nodes need the same configuration, and whether a Moodle upgrade is running at the same time. Ask for a timeline in the written scope that separates staging validation from the production change window, and confirm which of your change approvals apply.
What must our team provide before a Moodle proxy engagement starts?
Start with the items that determine how traffic reaches Moodle:
- A current network diagram showing every hop from the client to the Moodle web nodes, including CDNs, WAFs and load balancers
- The TLS certificate chain, the hostnames and the places where TLS ends
- Administrative access to the load balancer or a change request path that your network team controls
- The Moodle version and the web server or PHP stack in use, including the document root, since Moodle 5.1 requires the web server to point at the
publicdirectory - Access to the Moodle configuration file and a staging copy of the site for testing
- The list of IP-restricted quizzes, logging needs and any external systems that call Moodle
Can our own platform or network team configure Moodle behind a load balancer without a partner?
Yes, if the team has experience with Moodle's configuration file, web server routing and the load balancer in use. The work is well defined, but the failure modes cross team boundaries: a setting that is correct for Moodle can still break logins if the proxy rewrites headers or the load balancer keeps sessions on the wrong node. The questions to answer internally are who owns the load balancer change process, who will test sessions and quiz access from outside the network, and who will keep the setting correct through future Moodle upgrades. A partner is most useful when those responsibilities span several teams or when the environment is already under time pressure, for example before an exam period.
Why does a wrong sslproxy or reverseproxy setting cause login loops, mixed content and broken redirects?
Moodle builds its own URLs and decides whether a request arrived over HTTPS from the settings it has been given. If sslproxy is off while TLS ends at a load balancer, Moodle sees plain HTTP from the proxy and generates links, which browsers block as mixed content and which can send users into redirect loops. If reverseproxy is set when no proxy sits in front of the site, Moodle trusts forwarded headers that clients can send themselves, which affects logs, IP checks and the security report. Mismatches between the proxy's forwarded headers and what Moodle expects also break cookie domains and session cookies. Check the wwwroot` value, the forwarded protocol header from the proxy and the cookie settings together, because fixing one in isolation often produces a different failure.
Will IP-restricted quizzes and Moodle logs still work after we add a load balancer?
They work only when the real client address reaches Moodle. Behind a load balancer, the socket address Moodle sees is the proxy's address, so IP restrictions on quizzes and the IP recorded in logs will be wrong unless the proxy forwards the client address in a header and Moodle is configured to trust that header from the proxy only. Trusting forwarded headers from any source allows users to spoof addresses, which defeats the restriction. Confirm the header name your load balancer sends, the addresses of the proxies allowed to set it, and test a quiz restriction from both inside and outside your network before go-live.
Do we need shared sessions or sticky sessions behind the load balancer?
Sticky sessions are the simpler option because each user stays on one web node, but they make node failure and scaling harder and can concentrate exam-day load on a few nodes. Shared sessions, usually in Redis, let any node serve any request, which suits clusters but adds a dependency and requires session configuration that the rest of your stack must support. The choice affects health checks, drain behavior during deployments and the lock settings that cron and sessions use. Decide it with the scaling plan for the cluster rather than only for the proxy, and confirm how your load balancer implements stickiness and what it does when a node fails health checks.
How DeployOpen scopes a Moodle proxy change
A proxy change to Moodle starts with a written scope, because the work touches more than one file. DeployOpen agrees in writing which load balancer or TLS terminator sits in front of Moodle, which web nodes receive traffic, whether sessions are sticky or shared, and which settings in config.php will change, including $CFG->sslproxy, $CFG->reverseproxy and the wrapper URL. Most engagements of this kind are fixed-scope, so the deliverables, the environments covered and the acceptance checks are fixed before any change window is booked. DeployOpen works on self-hosted Moodle inside your own cloud accounts, data centers or networks, so the scope also records who holds the load balancer, DNS and certificate keys, and who approves changes to them.
The topology review comes next and is where most surprises are found. DeployOpen maps each hop a request takes, from the client through the TLS terminator and load balancer to the web servers, and records what each hop sets in X-Forwarded-For, X-Forwarded-Proto and Host. The review confirms whether Moodle sees the original client IP for logs and for IP-restricted quizzes, and whether any proxy in the chain strips or overwrites those headers. It also confirms the health check path and the stickiness rules the load balancer uses. Your network team should confirm which proxy addresses are trusted, since Moodle must only believe forwarded headers from them.
The change itself is staged: a non-production copy with the same proxy layout, then one web node in production, then the rest of the pool, with checks at each stage. Verification covers login over HTTPS, redirects that do not fall back to HTTP, correct client IPs in the logs, quiz access rules that depend on IP, and a session test that confirms users stay signed in when requests land on different nodes. DeployOpen then hands over the final configuration, a rollback procedure and a short runbook so your team can operate the setup after the engagement closes.
How DeployOpen delivers Moodle load balancer and proxy work
DeployOpen plans and builds Moodle behind a load balancer or TLS terminator in infrastructure you control, starting from a written scope that names the proxy chain, the session model and the client IP requirements. The work is handed over with configuration, tests and runbooks your own team can operate after go-live.
How we scope
- We map every hop between the browser and Moodle, including TLS termination, the load balancer and any reverse proxy.
- We record which pages need the client IP for logs and IP-restricted quizzes, and who owns those rules.
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
How we build
- We set the Moodle proxy settings for your topology and confirm the web server document root for your Moodle version.
- We configure health check endpoints and forwarded client IP handling, then test them against real request paths.
- We decide session stickiness or shared sessions with you, and document the trade-offs for your traffic pattern.
How we hand over
- You receive the final proxy and web server configuration, session settings and a record of each design decision.
- We provide test results for TLS, redirects, login, file downloads and IP-restricted quiz access.
- We walk your platform and security teams through the runbook for changing proxies, certificates and nodes.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after handover.
- We retest the proxy chain after Moodle upgrades, load balancer changes or certificate renewals.
- Confirm with your team which proxy and load balancer features your infrastructure supports before the scope is signed.

