localhost refused to connect - MAMP Pro

2019-05-19 07:51发布

问题:

There seem to be a few questions that are similar but could not find the answer.

An hour ago (and the months before that :-)) everything was working fine. It looks like after updating to XCode 9.2 things stopped working.

I've justed updated to MacOS High Sierra 10.13.2 as there were some Apache updates included, but it didn't solve the issue. Maybe the XCode update changed something to the httpd.conf file? I'm not too familiar with the settings in there, so I'm unable to determine if something changed in that file.

Error in Chrome:

This site can’t be reached

www.example.dev refused to connect.

ERR_CONNECTION_REFUSED

My setup:

MacOS High Sierra 10.13.2

MAMP Pro 4.2 (latest version)

Ports are Apache: 80 and MySQL: 3306

VPN is off

If I run sudo nano /private/etc/hosts it has the following entries (I run my local website on www.example.dev)

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
127.0.0.1       www.example.dev # Note; I added this myself a long time ago as else the URL including www doesn't work
127.0.0.1       example.dev       # MAMP PRO - Do NOT remove this entry!
::1             example.dev       # MAMP PRO - Do NOT remove this entry!

What I tried:

  • Changing ports to default MAMP ports (Apache: 8888 and MySQL: 8889). No luck
  • If I run apachectl configtest in terminal it returns Syntax OK

UPDATE

Just saw that if MAMP Pro is off:

  • It still gives the same error in Chrome
  • It still returns Syntax OK with apachectl configtest

When I run sudo apachectl stop it returns /System/Library/LaunchDaemons/org.apache.httpd.plist: Could not find specified service

UPDATE 2

Out of frustration I downloaded Firefox to check and... all my local dev sites work there! In Chrome I still get the same error, even after clearing browsing data.

回答1:

Turns out, Chrome (and Safari as well) were redirecting to https, so https://www.example.dev. And the problem was the .dev TLD.

If you run into the same problem (force forward by Chrome to https) and:

  • You DON'T use .dev, read this post for possible solutions
  • You DO use .dev as your local TLD, you need to change it to something else. Chrome redirects .dev TLDs to https since version 63. See this article and your best alternative TLDs here.


标签: apache mamp