Remove HSTS header, redirect to WWW, and make HTTPS work

I turned off HSTS but when I look at my headers I still get this:

http://nollywooddb.com
HTTP/1.1 200 OK
Date: Fri, 21 Dec 2018 16:23:43 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Set-Cookie: __cfduid=dca2eb6b9276566909cde14d008116b711545409423; expires=Sat, 21-Dec-19 16:23:43 GMT; path=/; domain=.nollywooddb.com; HttpOnly
X-Dns-Prefetch-Control: off
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Sun, 09 Dec 2018 17:07:51 GMT
Via: 1.1 vegur
Server: Cloudflare
CF-RAY: 48cbb1e342d7559a-ORD

I wonder why itā€™s there if Iā€™ve turned it off. But I really wouldnā€™t mind if HTTPS was working. I set it up with a heroku server and no matter what I do it says something like HTTPS is not supported for this setting.

Before getting crazy with HTTPS however, I want to know how I can get my heroku app to always redirect to www. Hereā€™s what my current setting looks like:

What am I doing wrong? I left all these 13 days ago hoping whatever cache would be busted by now

It could be set at your origin server. Try this with your serverā€™s IP address (all in one line):

curl -svo /dev/null --resolve nollywooddb.com:80:123.123.123.123 http://nollywooddb.com/

@sdayman Is that curl command supposed to clear my dns cache to remove the HSTS header?

Itā€™s to check your origin server for HSTS headers.

Hereā€™s what I got from that:

* Added nollywooddb.com:80:123.123.123.123 to DNS cache
* Hostname nollywooddb.com was found in DNS cache
*   Trying 123.123.123.123...
* TCP_NODELAY set

You didnā€™t replace 123.123.123.123 with the IP of your server, so youā€™re not getting anywhere.

You just made the Chinese Unicom sad :smile: :wink:

I got the same result with my server IP address. I expected to get something better as feedback.

If you get the exact same result (stuck at ā€œTCP_NODELAYā€ set) that would mean that youā€™re un-able to connect to your server at allā€¦ if the server is up, that would mean that youā€™re firewalled out?

Perhaps the server is behind some NAT and youā€™re attempting within the NAT? If thatā€™s what you do, then you need to use the internal IP of the server, not the public facing oneā€¦

Iā€™d forgo the HSTS header issue for a bit. Can I get some tips on how to get redirection to www working? Or how to make the enforced HTTPS work?

Right now, both www and the naked domain work over HTTP.

If I try to reach them with HTTPS, it redirects HTTPā€¦and still works.

To get the naked domain redirected to the www, add a page rule:
Match: nollywooddb.com/* and add a Setting for Forwarding URL (Code 301) to http://www.nollywooddb.com/$1

Note that I redirect to HTTP. If you switch over to HTTPS, then change that forwarding url to https.

Thank you @sdayman . Now to tackle my HTTPS problem, I turned it on again as Full Strict. Visiting this URL https://www.nollywooddb.com/ , I get a 525 Error that the SSL configuration used is not compatible with Cloudflare. What can be done to fix that? What I noticed however, is that the HTTP version uses HTTP 1.1 meanwhile the HTTPS version used HTTP v2

Iā€™d have to see the TLS certificate on the origin server (does it even have one?) to see what the problem is. It sounds like Cloudflare doesnā€™t like whatever it is. Have you tried using the Full (not strict) setting?

Thereā€™s no cert from the origin server. I just switched to Flexible because it works. Full gives the same error. Iā€™d suppose Flexible means it should proceed whether or not thereā€™s TLS cert from origin server. Iā€™m using heroku and I donā€™t think it offers certs for free. Iā€™ll have to purchase it I guess

Can I just keep it at flexible and turn on Always use HTTPS?

Without a certificate on your server youā€™ll have to use Flexibleā€¦but it would sure be nice if you were able to install a cert on the server.

Stick with Flexible, and turn on Always Use HTTPSā€¦and Automatic HTTPS Rewrites.

Thank you so much for all your help!!

2 Likes

You can use Full mode (or even Full(strict) mode last I checked) with Heroku on Cloudflare w/ any plan. Hereā€™s what you need to do:
ā€¢ Point www.example.com CNAME my-app.herokuapp.com [orange-cloud]
ā€¢ Go to Crypto ā†’ Origin Certificates ā†’ Create Certificate (keep the default settings). These are free
ā€¢ Keep the module with the Public and Private Key open.
ā€¢ Go to your Heroku app ā†’ Settings ā†’ Configure SSL ā€”> Paste Contents:

frank-io%20%C2%B7%20Settings%20%7C%20Heroku%202018-12-24%2000-08-00 frank-io%20%C2%B7%20Settings%20%7C%20Heroku%202018-12-24%2000-08-19
ā€¢ Finally, go into Cloudflare Workers (perhaps you donā€™t need to do this anymore, Iā€™m not sure) and add this snippet:
addEventListener(ā€˜fetchā€™, event => event.respondWith(handle(event.request)))

async function handle(request) {
  let url = new URL(request.url)
  url.hostname = 'my-app.herokuapp.com'
  return fetch(url.toString(), request)
}

ā€¦ and set the route to www.example.com/*
ā€¢ Turn on Always Use HTTPS

Voila! Full mode means that the Origin Server needs to have an SSL certificate served. That certificate can be self-signed, from Letā€™s Encrypt or (for optimal performance and security directly from Cloudflare)!

2 Likes

@franklin this is really useful and helpful information but I canā€™t configure SSL yet on Heroku because Iā€™m not using a paid dyno. Iā€™m still on the free dyno because my app is at alpha and Iā€™m not willing to put money into it yet. I believe your answer will remain valid for me to reference when I do make an upgrade on heroku. Then Iā€™ll try to change from Flexible to Full HTTPS

1 Like

:grimacing::cold_sweat::scream::rage::confounded:

:stuck_out_tongue_winking_eye::crazy_face:

1 Like