Domain works with www, but not without the www

I am hosting a nodejs server with a static site in a docker container on fly.io.
I own a domain that i purchased through hover.com, and i set up the DNS records as such:

However, although https://www.mydomain.com works, http://mydomain.com works, but https://mydomain.com/ doesn’t.

I get:

This site can’t be reached

poshfob.com unexpectedly closed the connection.

Try:

ERR_CONNECTION_CLOSED

@user84 Does the your Fly dashboard give you the green light on your certificate DNS validations? That _acme-challenge entry doesn’t look complete to me — I would have thought you’d need two entries there for _acme_challenge.www.mydomain.com and _acme-challenge.mydomain.com for all your URLs to work correctly.

Sorry i mean to reply to my own… i had a cert for *.mydomain.com, but i also needed one for mydomain.com. Honestly not sure why that fixed it but it did!

1 Like

Although now im struggling how to get http to auto-redirect to https when i am deploying a static site?

Is this still the nodejs app you’re referring to? If it is you’d probably want a middleware that checks the protocol and redirects if it’s http. But this will need to be some kind of behaviour change either way.

I have the opposite of this persons problem. I have a custom domain working at example.com, but I want it to work with the “www” as in "www.example.com". So I want both to work.

Scenario
• Running a Phoenix 1.6 application with Postgres
• I have everything running with very little configuration. So far so good.

Question

  1. Does my Phoenix or Elixir application need to be configured to interpret “www”?

  2. Do I need to add anymore information to my DNS provider so that if someone types “www.example.com” it will be directed to. Right now “example.com” works but I want “www” to work.

  3. When I ping “example.com” I get a response but when I ping it with “www.example.com” it doesn’t work.

  4. Do I need to create 2 SSL certificates? Example A vs Example B

Example A - in this example I have the wildcard in quotes
flyctl certs create example.com
flyctl certs create “*.example.com”

Example B - in this example I have www.example.com but not in quotes
flyctl certs create example.com
flyctl certs create www.example.com

I have run this command so far.
flyctl certs create example.com

The example here says it’ll be like in A for using wildcard, i.e, with quotes.

SOLVED IT
I think I figured out how to get it working. I had to refresh myself on the differences between CNAME vs A Records

STEPS

At this point wait until things have propagated 5 - 15 minutes.

You will know things are working because your certificates are valid and you should be able to visit your custom domain at example.com without the www.

My Understanding
Here is a screenshot of what my final records and record types looks like. (The value column has dummy data but the entries should help anyone understand how the records could be set up.)

Everything highlighted are the records I had to add from the flyio steps mentioned in the steps above (2 A Records, 1 AAA Record, 2 CNAME Records)

In order to get it to work with the www you need to create a CNAME record that points to your root domain. Most of my problem was a result of the CNAME | WWW | record not containing the value of my root domain example.com.

If anything looks incorrect let me know. Hopefully this helps anyone.

Verifying through the terminal

> host www.example.com
  www.example.com is an alias for example.com.
  example.com has address 66.255.125.99

> host example.com
  example.com has address 66.255.125.99
1 Like