Setting up a custom domain on PythonAnywhere
If you have a paid account on PythonAnywhere, you can set up web apps on your own domain -- that is, a domain that is not your-username.pythonanywhere.com
Configuring the domain at the domain registrar
To use your own domain name with a PythonAnywhere web app there are two steps
Purchase a domain name from a domain name registry.
Create a CNAME record for (say) www.yourdomain.com pointing to your-username.pythonanywhere.com. This tells the domain name system that when someone asks for your website, they should get it from us. All of your domains should point to the same target, your-username.pythonanywhere.com, we'll take care of showing the right web app on the right domain.
Domains without a www prefix (naked domains)
One small problem with setting up DNS like this is that it doesn't allow "naked domains" -- that is, you can have your site at www.yourdomain.com or somethingelse.yourdomain.com, but not at just yourdomain.com. Here's some more information about that, and some recommendations.
CNAME records have two parts. The Alias and the Canonical Name. The alias in this case should be www. The address should be your-username.pythonanywhere.com.
Different DNS providers call them different things. So:
- Alias, AKA: domain name, Alias name,
- Canonical Name, AKA: the address, FQDN, Fully Qualified Domain Name, or Host Name.
Testing your configuration
Use this CNAME lookup tool. Enter your domain name including the www. It will take a few seconds. In the results, if the Canonical Name is anything other than your-username.pythonanywhere.com or it doesn't even show you a result for Canonical Name then you have either not set it up properly. Or you need to wait longer for the configuration changes to take effect.
Specific DNS providers
Associating a PythonAnywhere web app with your domain
If you want to create a new web app associated with the domain, just click the "Add a new web app" button on the Web tab, and specify the domain on the first page.
If you want your domain to show a web app that you've already created, the process is a little more complicated. Let's say that the app you want to show is currently displayed at fred.pythonanywhere.com, and you want it to appear at www.yourdomain.com. Once you've done the CNAME setup as described above, here's what you do:
Click the "Add a new web app" button, and on the first page specify your domain (exactly as you did at the registrar -- don't forget the www if you used it there).
- On the next page, select "Manual configuration", then click next and complete the setup process. This will set up a web app on your domain with a simple "Hello world" kind of page.
Now comes the more difficult bit; you need to replace the PythonAnywhere configuration for your new domain with the one for the old domain. This configuration is done by files inside /var/www in your account. Each domain you are running a web app for has a file there named after the domain, with dots replaced by underscores and _wsgi.py at the end.
- So: start a bash console
- In it, copy the configuration for your existing app on top of the new app, with a command like this (don't forget to change the filenames to match your original domain and your new domain:
cp /var/www/fred_pythonanywhere_com_wsgi.py /var/www/www_yourdomain_com_wsgi.py
- Finally, go back to the Web tab and reload the web app for your new domain.
That should do the job.