Symptoms & Diagnosis
The “Safari can’t connect to the server” error often appears when developers try to access applications running on localhost. This specifically manifests as a connection refused message, preventing you from previewing your work.
Common symptoms include the browser failing immediately without a timeout or a message stating that the server dropped the connection. Diagnostic steps involve checking if the service is reachable via the terminal or other browsers.

If you can access the site via Chrome but not Safari, the issue likely stems from Safari’s strict security protocols or DNS handling. If it fails everywhere, the local server process itself is likely offline or misconfigured.
Troubleshooting Guide
1. Verify the Port and Server Status
The first step is ensuring your local development server is active and listening on the expected port. You can verify this using the terminal to see which processes are running.
sudo lsof -i -P -n | grep LISTEN
If your port (e.g., 3000 or 8080) does not appear in the list, your server is not running. Restart your development environment or Docker container.
2. Use 127.0.0.1 Instead of Localhost
Safari sometimes struggles with resolving the “localhost” hostname due to IPv6 preferences. Replacing the text “localhost” with the direct loopback IP address often bypasses this resolution error.
Try navigating to http://127.0.0.1:8080 instead of http://localhost:8080. This forces the browser to connect directly to the local machine without a DNS lookup.
3. Check for Forced HTTPS
Safari is aggressive about upgrading connections to HTTPS. If you have previously visited a site with the same name over a secure connection, Safari may refuse to load the HTTP version of localhost.
Clear your Safari history or use a Private Window to see if the error persists. You should also ensure you are explicitly typing http:// in the address bar.
Summary of Troubleshooting Steps
| Potential Cause | Resolution Method |
|---|---|
| Process Not Running | Restart your local server (npm start, etc). |
| DNS Resolution Failure | Use 127.0.0.1 instead of “localhost”. |
| HSTS / HTTPS Issues | Clear browser cache or use Private Browsing. |
| Port Conflict | Kill the process on the port and restart. |
Prevention
To prevent the localhost connection refused error in the future, ensure your /etc/hosts file is properly mapped. You can inspect this file with the following command:
cat /etc/hosts
Ensure that 127.0.0.1 localhost is present. Additionally, avoid using .local or .dev custom domains without valid SSL certificates, as Safari’s modern security features may block these connections automatically.
Regularly flushing your DNS cache after changing network configurations can also keep your local development environment stable.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder