Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari keeps forcing HTTPS on localhost

When I load http://localhost:3000 in Safari, Safari automatically redirects to https://localhost:3000. How can I disable this functionality?

I went into ~/Library/Cookies/HSTS.plist and removed the localhost entry, then restarted Safari but it just re-added it to that plist file and redirected to https.

Any ideas how to fix this so that on localhost I have to explicitly say http or https?

like image 739
Charlie Fish Avatar asked Sep 24 '17 20:09

Charlie Fish


People also ask

How stop HTTP redirect HTTPS?

To the right of your domain, click the Settings button. In the AUTOMATIC HTTPS IS ENABLED FOR THIS SITE section you will see a green lock icon. Click Change Automatic HTTPS Setting. Then click the Disable Automatic HTTPS button.

Does Safari always use HTTPS?

Unlike Chrome, Edge, and Firefox, Safari doesn't have an HTTPS-only mode. However, what it does have is the ability to automatically switch sites from HTTP to HTTPS if available. The feature is enabled by default with Safari 15 on macOS Monterey, macOS Big Sur, and macOS Catalina.

Why localhost is not working in Safari?

Issues Connecting to Localhost with Safari Follow When asked to make some types of connection to localhost or 127.0. 0.1, Safari may ignore any configured proxy. This may cause Safari to not fetch traffic via Sauce Connect, causing tests to fail. To prevent this, use a different hostname for the system under test.


2 Answers

I was able to solve this based on an answer from Ask Different.

In short, closing Safari, then running the commands below, worked.

sudo killall nsurlstoraged rm -f ~/Library/Cookies/HSTS.plist launchctl start /System/Library/LaunchAgents/com.apple.nsurlstoraged.plist 

Restarting Safari after running that and trying to go to http://localhost:3000 solved the problem and did not redirect to to https.

Hopefully this helps someone fix this problem.

like image 150
Charlie Fish Avatar answered Sep 20 '22 18:09

Charlie Fish


In Safari 13.0.5, deleting website data for localhost (Safari > Preferences > Privacy > Manage Website Data...) solves the problem.

Safari > Preferences > Privacy Manage Website Data...

like image 29
David Moles Avatar answered Sep 18 '22 18:09

David Moles