Proxy localhost and loopback addresses in Chrome
- Workaround
- Override Chrome Implicit Bypass Rule via cmd/shell
- Override Chrome Implicit Bypass Rule via SwitchyOmega
- Fix ERR_CONNECTION_REFUSED
- Fix ERR_EMPTY_RESPONSE
- Fix ERR_SSL_PROTOCOL_ERROR
- If things are still not working…
- References
Since Chrome 72, requests to localhost (127.0.0.1) or link-local IP do not go through a proxy by default.
Requests to certain hosts will not be sent through a proxy, and will instead be sent directly.
We call these the implicit bypass rules. The implicit bypass rules match URLs whose host portion is either a localhost name or a link-local IP literal. Essentially it matches:
localhost *.localhost [::1] 127.0.0.1/8 169.254/16 [FE80::]/10
The complete rules are slightly more complicated. For instance on Windows we will also recognize
loopback
, and there is special casing oflocalhost6
andlocalhost6.localdomain6
in Chrome's localhost matching.
Workaround
The easiest workaround is to simply access your remote localhost via a globally resolvable hostname, e.g.
local.test.cab
*.local.test.cab
But if your remote localhost is configured to allow connections from hostname localhost only, then you need to configure chrome to ignore the implicit bypass rule.
Override Chrome Implicit Bypass Rule via cmd/shell
To override the implicit bypass rule, you can run chrome with the following command line flag on Windows:
"%LocalAppData%\Google\Chrome SxS\Application\chrome.exe" --proxy-bypass-list="<-loopback>"
or on Linux:
google-chrome --proxy-bypass-list="<-loopback>"
chromium --proxy-bypass-list="<-loopback>"
Override Chrome Implicit Bypass Rule via SwitchyOmega
If using SwitchyOmega Chrome extension, proxy of Chrome is controlled by it, so we need to add <-loopback>
into Bypass List of the profile configured in the extension.
Fix ERR_CONNECTION_REFUSED
When you see this error, it may be caused by your request not going to the proxy server. Please recheck you've configured chrome to override implicit bypass rules correctly.
Fix ERR_EMPTY_RESPONSE
If you've configured chrome to ignore the implicit bypass rules, but still can't get access to the website hosted on your proxy server via localhost
:
You need to check whether you've input the correct port number.
And to check whether there is an entry for localhost in /etc/hosts
file on the proxy server:
127.0.0.1 localhost
If not, add the above line to the file, and try reloading the page.
Alternatively, simply access it via IP address 127.0.0.1
Fix ERR_SSL_PROTOCOL_ERROR
If you see the SSL error, you're accessing an HTTP site via HTTPS.
This may be caused by either incorrectly entering https://
instead of http://
, or HSTS policy set to the localhost domain.
You can query and clear the HSTS status in chrome via <chrome://net-internals/#hsts> Query Expect-CT domain and Delete domain security policies.
If things are still not working…
Check the log of your proxy server. Please note that some proxy servers are configured to disallow connections to localhost, so you may have to configure the proxy sever itself.