Rails tenanted app with CloudFlare and subdomains

632 Views Asked by At

I'm building a tenanted Rails application on Heroku which uses subdomains for each tenanted instance. The problem is I can't seem to get CloudFlare to properly cache a subdomain.

I have my Application hosted on heroku at say whatever.herokuapp.com And using CloudFlare I'm pointing my main application at heroku's CNAME (whatever.herokuapp.com) and that works fine. I'm using a wild cards *.mydomain.com on Heroku and then using CloudFlare again to point at them.

So say I create an app myinstance.mydomain.com on CloudFlare -> whatever.herokuapp.com because I'm using the *.mydomain.com on Heroku it works fine.

BUT when I try to turn on the Acceleration (CloudFlare caching) it immediately breaks and all I see is a CloudFlare error Error 1001 telling me:

Most likely: if the owner just signed up for CloudFlare it can take a few minutes for the website's information to be distributed to our global network.

2

There are 2 best solutions below

0
On BEST ANSWER

From their help desk:

Fundamentally in a standard set up the domain needs to be added to CloudFlare in order for us to understand how to route traffic for that domain.

If you wanted a setup where anybody in the world could CNAME to your CloudFlare configuration, that is possible but it's an Enterprise feature. We call it "Managed CNAME" - if that's something you're interested in do let me know and I can put you in touch.

FYI, CloudFlare Enterprise averages at $5,000 a month.

CloudFlare is great in that it just works without much customization starting at zero cost, but unless your multi-tenanted app is for Bank of America or other Fortune 500 company I'd suggest something like Fastly ($5-50/month) or some other DIY caching solution that allows you to setup caching as you need rather than a one-size-fits-all top down solution.

https://devcenter.heroku.com/articles/fastly

Works directly with Heroku but there might be other solutions that work equally well.

0
On

That error can also occur if you're pointing a domain/subdomain not on CloudFlare to a domain that is on CloudFlare (creates a DNS resolution lookup error). I would probably contact CloudFlare support for additional assistance and troubleshooting.