Is there a way to set up a Cloudflare load balancer across 2 or more Pythonanywhere web apps?
I have successfully set up a Cloudflare load balancer with a Pythonanywhere US app and Pythonanywhere EU app. Here's how it is currently set up:
- Create duplicate web apps on both the US and EU instances of Pythonanywhere, both named app.mydomain.com
- Create CNAME DNS records for the two web apps: primary.mydomain.com > webapp-{us-app-id}.pythonanywhere.com, backup.mydomain.com > webapp-{eu-app-id}.eu.pythonanywhere.com
- Create two Cloudflare load balancer pools: endpoint addresses: primary.mydomain.com, backup.mydomain.com and add a Host header to both set to app.mydomain.com
- Create the Cloudflare load balancer pointed to app.mydomain.com, with the primary pool set to receive 100% of traffic and the backup pool as the fallback pool.
- Create Origin SSL certificate in Cloudflare and add it to both Pythonanywhere apps as a custom SSL certificate.
This setup works exactly as planned, with the primary, US-based web app receiving 100% of traffic as long as it is healthy. Cloudflare pings both servers every 60 seconds and automatically begins routing traffic to the backup only if the US server is down.
Because of it's physical location and distance from the database, the EU server is noticeably slower at responding to requests. I want to set up a second US-based instance as a backup (or potentially to share to load of the primary server), while keeping the EU server as the fallback for both US servers. Pythonanywhere enforces a limit that only one web app on their platform can have the same domain, preventing me from using this configuration for two US-based apps. Has anyone figured out a way to set this up?