localhost invalid response / ERR_SSL_PROTOCOL_ERROR: fix
Fix ERR_SSL_PROTOCOL_ERROR and invalid response errors on localhost: use http, clear the saved HTTPS rule, or set up a trusted local certificate.
These errors usually mean the browser used https:// but your local server only speaks plain http, so the secure handshake fails. Often Chrome added https on its own, because of a saved rule for localhost.
What to do, step by step
- Type the full address with http://, for example http://localhost:3000.
- If Chrome keeps switching to https, open chrome://net-internals/#hsts, type localhost under "Delete domain security policies" and click Delete.
- Clear the saved redirect: in Chrome open Settings, Privacy, then delete the cached files for the last hour.
- If you really need https locally, create a trusted certificate with mkcert (steps below) and configure your server to use it.
- Restart the dev server and open the address again.
Commands you can copy
mkcert -installmkcert localhost 127.0.0.1 ::1Other causes to check
- NET::ERR_CERT_AUTHORITY_INVALID on https://localhost
- The certificate is self-signed and not trusted. Use mkcert to make one your computer trusts, or accept the warning once for testing only.
- Firefox shows SSL_ERROR_RX_RECORD_TOO_LONG
- Same cause: https:// was used on a plain http port. Switch to http://.
- A redirect rule sends you to https
- Remove the HTTPS redirect from your local server or .htaccess while you develop.
- Port 443 vs your dev port
- https://localhost uses port 443 by default. If your server runs on 3000, write the port and the scheme that matches it.
Questions about localhost https SSL error
- Do I need https on localhost?
- Usually not. Browsers treat localhost as a secure context, so most features work on plain http. You need https only to test things like secure cookies behind a real domain name.
- What is mkcert?
- A small tool that creates a certificate authority on your own computer and certificates that your browser trusts. It is meant for development only.
- Is it safe to click "proceed anyway"?
- On your own localhost it is fine. Never do it on a real website with a certificate warning.
Config generators for this
- nginx HTTPS server blockServe your site over HTTPS with nginx: certificate paths, HTTP to HTTPS redirect, HSTS and a proxy or static site.
- nginx redirect www to non-wwwSend www.example.com to example.com (or the reverse) with one permanent redirect.