Thanks, Cartroo -- that's a great primer! One correction: we ask people to create their CNAMEs pointing to theirusername.pythonanywhere.com
, not just pythonanywhere.com
. In the light of your explanation, perhaps I can explain why that's useful, and why we don't just ask people to create an A record pointing to our main IP address.
Right now, the number of sites hosted on PythonAnywhere is small enough that everyone can be behind the same nginx reverse proxy -- that is, everyone's site actually sits at the same IP address, but the hard work of serving sites can be farmed out by nginx to other servers so we can scale up the number of sites we support just by adding more servers behind nginx.
But let's imagine some time in the future, when we have tens of thousands of domains hosted at PythonAnywhere. (We're getting there.) We can't have them all pointed at the same IP address, because even if we run a super-fast nginx server on that IP address to delegate the work of each website to a separate web server, we still wind up with all of the traffic for all of the domains going through the same network port, which obviously won't work, however fast it is.
So, we want to be able to separate out the traffic for each of our users so that we can point, say, user giles
' traffic to one computer and user donthireddy
's traffic to another. giles
might share an IP with a bunch of other users, and likewise donthireddy
with a different group of other users, but they each have a different IP.
The thing is, we'll need to adjust who uses which IP dynamically; that is, we might want to switch donthireddy
's site from one IP address to another as we balance out the load between our servers. But we don't want donthireddy
to have to log in to his DNS provider every time we change the IP address, because that would be a pain for everyone.
So, right now giles.pythonanywhere.com
and donthireddy.pythonanywhere.com
both point to the same IP address. That IP address is controlled by us, using our own DNS servers. But with just a slight change, we can switch the names over so that they point at different IPs. Which means that if giles
has a domain with a CNAME pointing at his PythonAnywhere subdomain, and likewise donthireddy
has one pointing at his own subdomain, we can make a simple DNS change and both of their domains are suddenly being served by a different proxy, so we can scale up without having to bother both of them and ask them to change their DNS settings.
It gets even better than that, though. Because CNAMEs give us control over the ultimate IP address that our users domains wind up at, we can also route different requests to different IPs. This means that for a particular domain we can start sending half the requests to one IP and half to another (using something like round-robin DNS). This means that at some point in the future we can start making it easy for people to run high-availability sites served from multiple IPs, which is great for load-balancing and reliability.
Hope that's reasonably clear and helpful!