Repository navigation
Description
Recently, I set up CloudFlare with Heroku to make good use of its Universal SSL and essentially made Dasherize https the poor man's way.
My aim was to get the following working:
http://dasherize.comredirects tohttps://www.dasherize.comhttp://www.dasherize.comredirects tohttps://www.dasherize.comhttps://dasherize.comredirects tohttps://www.dasherize.comhttps://www.dasherize.comworks!
Here are the steps to get that working:
1) Sign up for a CloudFlare account
Go to https://www.cloudflare.com/.
2) Add a website to CloudFlare
3) Configure CNAME
After you have scanned your website, you will probably see an A entry and a CNAME entry.
Modify (and/or delete) the A and CNAME entries so that they become:
CNAME,dasherize.comto Heroku domain nameCNAME,wwwto Heroku domain name
It might look strange to have two CNAME going to the same Heroku domain, but CloudFlare supports CNAME Flattening so we are good.
4) Wait for DNS to propagate
At this point, we can wait for DNS to propagate and when it's done:
http://dasherize.comredirects tohttps://dasherize.comhttp://www.dasherize.comredirects tohttps://www.dasherize.com
And the DNS entries should look like so (with some information ommitted):
$ curl -I http://dasherize.com
HTTP/1.1 301 Moved Permanently
...
Location: https://dasherize.com/
Via: 1.1 vegur
Server: cloudflare-nginx
$ curl -I http://www.dasherize.com
HTTP/1.1 301 Moved Permanently
...
Location: https://www.dasherize.com/
Via: 1.1 vegur
Server: cloudflare-nginx
$ curl -I https://dasherize.com
HTTP/1.1 200 OK
Server: cloudflare-nginx
...
Via: 1.1 vegur
$ curl -I https://www.dasherize.com
HTTP/1.1 200 OK
Server: cloudflare-nginx
..
Via: 1.1 vegur
We are almost there, we are just left with redirecting http://dasherize.com to https://www.dasherize.com.
You might be thinking.. But why www? Everyone has different opinions.
5) Final Redirection
To redirect http://dasherize.com to https://www.dasherize.com, we need to include add a Page Rule that:
Forwards (301)
https://dasherize.com/*tohttps://www.dasherize.com
And with that, the DNS entries will look like:
$ curl -I http://dasherize.com
HTTP/1.1 301 Moved Permanently
...
Location: https://dasherize.com/
Via: 1.1 vegur
Server: cloudflare-nginx
$ curl -I http://www.dasherize.com
HTTP/1.1 301 Moved Permanently
...
Location: https://www.dasherize.com/
Via: 1.1 vegur
Server: cloudflare-nginx
$ curl -I https://dasherize.com
HTTP/1.1 301 Moved Permanently
...
Server: cloudflare-nginx
Location: https://www.dasherize.com/
$ curl -I https://www.dasherize.com
HTTP/1.1 200 OK
...
Server: cloudflare-nginx
Via: 1.1 vegur
6) Full SSL
Finally, go to the Crypto page, and make sure that you have selected the Full option for your SSL. You can read more about the differences by clicking on Help below the select options.
With these 6 steps, you now have a SSL enabled site for $0, all thanks to CloudFlare's Full SSL option:
Since all Heroku apps comes free with https and that, quoting CloudFlare, "CloudFlare will not attempt to validate the certificate", hence it makes it easy for us to have the Dasherize site SSL-enabled.
Also, don't forget to set config.force_ssl = true in your Rails production.rb.
Thank you for reading.
About Jolly Good Code
We specialise in Agile practices and Ruby, and we love contributing to open source.
Speak to us about your next big idea, or check out our projects.






Activity
joshteng commentedon Nov 16, 2015
@winston tremendously helpful and cost saving tip!
winston commentedon Nov 16, 2015
@joshteng ka-ching!
fadhlirahim commentedon Nov 16, 2015
👍
tmlee commentedon Nov 16, 2015
@winston Nice that does the job in a few steps!
I supposed for something more granular, https://github.com/tobmatth/rack-ssl-enforcer can be considered?
winston commentedon Nov 17, 2015
@tmlee Yup. That gem seems to do the job.
faizalzakaria commentedon Nov 17, 2015
interesting.
lordhumunguz commentedon Jan 4, 2016
Thanks Winston!
the redirecting from http to https doesn't seem to be automatic. Did you have to turn it on somewhere? I get 200 OK's for both http and https.
joshteng commentedon Jan 4, 2016
@4thethrillofit I do a 301 http -> https redirection at my DNS. fyi, using cloudflare. But I think if ure still using Rails, there's a config to force ssl I think.
winston commentedon Jan 4, 2016
@4thethrillofit Is it a Rails app? As what @joshteng said:
lordhumunguz commentedon Jan 4, 2016
Yep! @joshteng apparently they want you to use Page Rules
joshteng commentedon Jan 4, 2016
@4thethrillofit it was weird at first but i got to love it fast enough. haha
choonkeat commentedon Jan 23, 2016
another day, another free SSL https://aws.amazon.com/blogs/aws/new-aws-certificate-manager-deploy-ssltls-based-apps-on-aws/
guptarohit commentedon Jan 25, 2016
Is dasherize.com hosting on heroku?
I am using shared hosting, how can I make it work.
In my case records looks like(I have removed 'A' records):
still not working, I also tried the value of A record(which I've removed now) in place of CNAME's value. Can you suggest possible solution?
winston commentedon Jan 26, 2016
@guptarohit Yes dasherize is hosted on heroku.
Is clcp.hostingprovider.com your actual application?
Is it because of a DNS propagation issue? Does it work already?
guptarohit commentedon Jan 26, 2016
@winston no clcp.hostingprovider.com is not my application.
My application is hosted by a hosting provider.
"clcp.hostingprovider.com" got inserted in CNAME while I setting up cloudflare. I'd just pointed my DNS to cloudflare's nameserver, that's all I did.
There was some IP address in A record(which I have removed).
winston commentedon Jan 26, 2016
Hmm.. First question.. does your hosting provider provide you with a https end point? If not, it's pretty futile to follow this guide. i.e. it only works with Heroku.
Next, is your application accessible via an IP address or URL? Try replacing "clcp.hostingprovider.com" with that. But again, if your app is not accessible at
https://<ip or url> on your hosting provider, like I said, this won't work. Hope this clarifies.guptarohit commentedon Jan 26, 2016
Exactly this is the problem,
https://<ip or urldoes not resolve to my application.👍 Thanks though for clearing my query. 😃