MAMP Pro问题:127.0.0.1返回Error 404但http://localhost可正常访问
Hey there, let’s dig into why 127.0.0.1 is throwing a 404 while http://localhost works fine in your MAMP Pro setup. Here are the most common fixes to try:
Verify Apache’s Listen Configuration
Open MAMP Pro, go to the Apache tab, and click thehttpd.confbutton to access the main Apache config file. Look for lines starting withListen:- If you see
Listen localhost:80(or your custom port), that means Apache is only listening for requests to thelocalhosthostname—not the IP address. Change it toListen 80(or your port number) to allow Apache to respond to all interfaces, including 127.0.0.1. - Save the file, restart Apache in MAMP Pro, and test
127.0.0.1again.
- If you see
Check Virtual Host Setup for 127.0.0.1
MAMP Pro’s virtual hosts might not have an entry for127.0.0.1, even iflocalhostis configured:- Go to the Hosts tab in MAMP Pro.
- If there’s no entry for
127.0.0.1, click the+button to add a new host. - Set the Hostname to
127.0.0.1, point the Document Root to the same directory as yourlocalhostsite, and make sure the Status is set to "On". - Save changes and restart Apache.
Confirm /etc/hosts File Mapping
Whilelocalhostworks, double-check that your system’s hosts file maps127.0.0.1correctly:- Open Terminal and run
sudo nano /etc/hosts. - Look for a line like
127.0.0.1 localhost—this should be present (and not commented out with a#). - If you want to explicitly map
127.0.0.1to itself, you can add127.0.0.1 127.0.0.1below that line. - Save the file (Ctrl+O, then Enter) and exit (Ctrl+X).
- Open Terminal and run
Check Apache Error Logs for Clues
The error logs will tell you exactly why the 404 is happening:- In MAMP Pro’s Apache tab, click the
Logsbutton and selecterror_log. - Look for recent entries that mention
127.0.0.1—you’ll see details like "File does not exist: /path/to/expected/file" or permission issues. - Fix the root cause (e.g., ensure the document root has an index file like
index.phporindex.html, or adjust folder permissions).
- In MAMP Pro’s Apache tab, click the
Verify Document Root Permissions
Make sure the folder you’re using as the document root for127.0.0.1has the right permissions:- Right-click the folder in Finder, select Get Info, and under Sharing & Permissions, ensure your user account has "Read & Write" access.
- You can also run
sudo chmod -R 755 /path/to/your/document/rootin Terminal to set standard permissions.
内容的提问来源于stack exchange,提问作者LaGriffeDigitale

