Visitor : 54

Read Comments

Cloudflare - Pythonanywhere DNS setup

Django Hosting


Pythonanywhere  is an Online IDE and webhosting service based on Python. Its a simple solution for hosting Django , Flash application which are build around python programming language. Cloudflare, Inc. is an American web-infrastructure and website-security company, providing content-delivery-network services, DDoS mitigation, Internet security, and distributed domain-name-server services.

This article explains basic steps involved in hosting Web applications in Pythonanywhere (PA) and using Cloudflare (CF) as DNS provider.

This article assumes that you have a website hosted in pythonanywhere environment , have a domain registered and account with CloudFlare for DNS management.

 

Python Anywhere uses CNAME for pointing the domain to their server. Hence you will be provided with a IP address but with CNAME. Inspite of various advantages 

the one restriction that CNAMEs have is that they cannot be used for "naked" or "apex" domains. To make that more concrete, you can use www.yourdomain.com or somethingelse.yourdomain.com for the website, but not yourdomain.com. But that doesn't have to be a problem; you can host your site on www.yourdomain.com and then set things up so that people who visit yourdomain.com are automatically redirected to www.yourdomain.com.

To overcome this restriction 

1.  You can either define a subdomain and assign it to PA (without www) : Subdomain mapping 

2. Use www subdomain

In either case only subdomain is to be assigned to PA webapp. Lets assume you have a domain called : greatwork.com.

 

Option 1 : Subdomain mapping

PythonAnywhere Setup

if you opt to use option 1 , you have subdomain , lets call it new. So your PA setup should be as follows : new.greatwork.com (without www)

 

CloudFlare Setup

Login to your cloudflare account and select the domain registered.

Select the DNS setup page.

 

Create a new CNAME sub domain with name new and assign PA CNAME (which can obtained from PA - Web page tab).

The limitation with this approach is when your site is displayed your main domain is not visible , and always the sub domain in visible in the address bar. If you would like to see your domain name directly them you may have to follow the second approach , which is to use www as your sub domain.

 

 

Option 02 : Use www  subdomain.

PythonAnywhere Setup

Maintain web app address in PA as www.greatwork.com.

 

CloudFlare Setup

Login to your cloudflare account and select the domain registered.

Select the DNS setup page.

You can follow either approach 1 approach 2 or approach 3. I prefer the 3rd option.

 

Approach 01

 Add a CNAME record with your domain pointing to www subdomain.

@ - > current domain name

 

Add record and a CNAME record with www as subdomain

 

When the users enters domain name : greatwork.com in our case its routed to subdomain www.greatwork.com which intern in directed to CNAME : webapp-XXXXX.pythonanywhere.com (PA site).

 

 

Approach 02:

A different approach can also be followed using Page Rules.  Page rules are used for forwarding request.

In our case we can CNAME record for www pointing to PA webserver.

and create new Page rule where all requests to our domain goodwork.com is forwarded to https://www.goodwork.com

 

With this setup any request to page goodwork.com is forwarded to subdomain www.goodwork.com which is routed to CNAME of PA server.

 

 

Approach 03 : Subdomain forwarding with A record.

Create a A record with 8.8.8.8 as forwarding to ip.

 

Create CNAME record for subdomain www pointing to PA - CNAME

Add record and a CNAME record with www as subdomain

 

 

Maintain page forwarding to Subdomain which is linked to PA CNAME.

 

Advantage with this approach is since the routing is with A (IP) address , it is always routed , in whatever way the user calls the main domain (Eg : www.goodwork.com or goodwork.com or https:\\goodwork.com)

 

 

Please note :

  • DNS propagation may take a day or more based on the service provider
  • Clear your cache / cookies every time before new setup
  • In case of certificate related error please ensure encryption is activated in CF.

 



Add Comments