Introduction
Since a few months ago, I have been experiencing random "connection refused" issues with Google Chrome. Sometimes certain web pages just won't load, but they work fine on other devices. Although it seemed strange, I thought it might be a server configuration issue and didn't cause much trouble, so I continued using it.
Setting up a custom domain
Later on, something strange happened when I casually bought a .dev
domain. After setting up the CNAME and ensuring that SSL was working, no matter how many times I refreshed in Chrome, it kept showing "CONNECTION_REFUSED". Typically, there are a few reasons for this issue. The first possibility is that the server hasn't opened the port, and the other is firewall settings. I checked both of these settings and found no issues. Just to be safe, I used dig xxx.dev +nostats +nocomments +nocmd
to verify if the CNAME was set correctly. Everything was fine.
Next, I checked the SSL issue. I used SSL checker to confirm if SSL was configured correctly, and it was.
Alright, maybe it takes some time for the settings to take effect, so I waited for 10 minutes and checked again. Still no luck, Chrome still showed the dreaded "CONNECTION_REFUSED". Then I tried accessing the website on my phone and found that it worked successfully.
At this point, I started to suspect that there might be some misconfiguration on my computer. So, I began checking the relevant settings. First, I used curl blog.kalan.dev
to see what would happen. The result showed an error:
curl: (7) Failed to connect to blog.kalan.dev port 80: Connection refused
Hmm, the result from Chrome and curl was the same, which made me even more certain that there was an issue with the computer's settings. Next, I used wget to see what was going on.
wget https://blog.kalan.dev
--2019-03-18 23:11:46-- https://blog.kalan.dev/
Resolving blog.kalan.dev (blog.kalan.dev)... 127.0.0.1, 0.0.0.1
Connecting to blog.kalan.dev (blog.kalan.dev)|127.0.0.1|:443... failed: Connection refused.
Connecting to blog.kalan.dev (blog.kalan.dev)|0.0.0.1|:443... failed: No route to host.
Wait a minute, it resolved to 127.0.0.1? Does that mean I added this domain to the hosts file on my machine? I had no recollection of doing that, but with a glimmer of hope, I checked the /etc/hosts
and /private/etc/hosts
files.
The result was still the same. I hadn't set the domain in the local hosts file. But at least I knew the reason now. Somehow, some configuration caused blog.kalan.dev
to be set to 127.0.0.1
. At this point, I had no idea what could have caused it. But as I was randomly trying things, I noticed something strange. I found that any xxx.dev
domain had the same issue, while other domains didn't.
Suddenly, I remembered something. About 4 years ago, I downloaded powder to learn Ruby On Rails. Essentially, it allows you to access websites and automatically starts the server for you. It's super convenient! So, I happily installed it back then.
However, upon closer inspection of the official documentation, I found that section 3.1 stated:
The
POW_DOMAINS
environment variable specifies a comma-separated list of top-level domains for which Pow will serve DNS queries and HTTP requests. The default value for this list are the twotest,dev
domains, meaning Pow will configure your system to resolve*.test
and*.dev
to 127.0.0.1 and serve apps in~/.pow
under the.test
and.dev
domains.
Oh, so that's why it hijacked my IP and pointed it to 127.0.0.1, and since my computer didn't have port 443 open, that's why I was getting "CONNECTION_REFUSED". So, those web pages I couldn't see were probably all using the .dev
domain.
A few things to note:
- When encountering "CONNECTION_REFUSED", use
wget
to check if the host connection is correct. - Alternatively, use
curl --ipv4 -v "your.site.com"
to check the host connection.