16

I have the following in my C:\Windows\System32\drivers\etc\hosts:

127.0.0.1 example.com

It works when I use: http://example.com

But does not work when I use: https://example.com, which gives error ERR_CONNECTION_REFUSED.

Any idea how to use hosts with an HTTPS site?

If not, any alternative?

Arjan
  • 31,511
yarek
  • 691

3 Answers3

12

The following in your hosts file

127.0.0.1 example.com

...makes both http://example.com and https://example.com go to 127.0.0.1, hence: your own machine. (Even more: anything that refers to example.com, such as ping or telnet would go to 127.0.0.1 when run from your computer.)

Apparently you have a web server running on your own computer on port 80 (HTTP), but nothing on port 443 (HTTPS). Even more, getting ERR_CONNECTION_REFUSED actually proves your hosts file is used, as otherwise you would see the default website from https://example.com.

Note that if you would have the server on your computer also support HTTPS on port 443, you'd get certificate errors, as there is no way you can buy a certificate for the domain example.com.

Arjan
  • 31,511
0

I got tricked thinking that the site serves traffic via https://example.com where in fact the URL is using a subdomain e.g. https://www.example.com In that case just add one more record to the hosts file with www.example.com like below:

127.0.0.1   example.com
127.0.0.1   www.example.com

Or in fact to avoid errors on local web server (if you are running one for development purposes)

0.0.0.0 example.com
0.0.0.0 www.example.com
0

The following in your hosts file, working for me:

127.0.0.1 https://example.com
127.0.0.1 https://www.example.com
Edward
  • 1