The proxy does not see requests to localhost
Browsers and operating systems send localhost past the proxy by default. How to lift that exception in Chrome and Firefox, get around it with a host name, and open a local server from a phone.
Why there are no requests
The proxy works, but requests to localhost never reach it. Browsers and the operating system assume your own computer needs no proxy and connect to the server directly:
- Chrome since 72 sends
localhost,.localhostnames,127.*,[::1]and link-local addresses direct. The proxy settings change nothing here. - Firefox since 67 also skips the proxy for
localhostand127.*. - The system proxy exceptions on Windows and macOS usually already list local addresses, so programs that take the system proxy skip them too.
Which fix to pick
- Debugging in Chrome or Firefox on this computer. Turn the exception off in Chrome or Firefox.
- Any browser, app or command-line tool. Open the server under another name.
- A phone. Open the computer's LAN address.
Chrome, Edge and other Chromium browsers
Chrome's settings have no switch for this exception. Only the
--proxy-bypass-list="<-loopback>" flag at browser launch lifts it, and then
requests to localhost go through the proxy.
Flags take effect only when a new browser process starts. If Chrome is already
open, a command without --user-data-dir just opens a window in the running
browser, and the flags are ignored. With --user-data-dir a separate Chrome
with a clean profile starts and runs next to your usual one:
# macOS
open -na "Google Chrome" --args \
--proxy-server="http://127.0.0.1:7070" \
--proxy-bypass-list="<-loopback>" \
--user-data-dir="$TMPDIR/chrome-proxy"
# Linux
google-chrome --proxy-server="http://127.0.0.1:7070" \
--proxy-bypass-list="<-loopback>" \
--user-data-dir=/tmp/chrome-proxy
# Windows
& "C:\Program Files\Google\Chrome\Application\chrome.exe" `
--proxy-server="http://127.0.0.1:7070" `
--proxy-bypass-list="<-loopback>" `
--user-data-dir="$env:TEMP\chrome-proxy"
7070 is Solpuga's default port. If you changed it in Solpuga or use another
proxy, put in your port. For Edge replace
"Google Chrome" with "Microsoft Edge" (macOS) or the path to chrome.exe
with C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
(Windows).
Without flags. If the system proxy is set manually, add <-loopback> to
the system exceptions. Chrome reads them and
stops sending localhost direct. This does not work when the proxy comes from a PAC
file or automatic detection, or while the same list still names localhost
or 127.0.0.1.
Firefox
- Open
about:configand accept the warning. - Find
network.proxy.allow_hijacking_localhostand set it totrue.
If Firefox's network settings say Use system proxy settings, localhost may also be in the system exceptions. Remove it there, or choose Manual proxy configuration and set the proxy in Firefox itself.
Another name for any browser or program
The exceptions match the name localhost and 127.* addresses. Open the same
server under another name and the browser does not recognise it as your
computer, so it sends the request to the proxy. The proxy resolves the name
and passes the request to the server.
A name in the hosts file. Add a line to /etc/hosts (macOS, Linux) or to
C:\Windows\System32\drivers\etc\hosts (Windows). Editing it takes
administrator rights:
127.0.0.1 myapp.test
Now open http://myapp.test:3000.
Not every name works. Chrome treats names ending in .localhost as localhost,
and names ending in .local are often in the system exceptions. On Windows
the name needs a dot, or the <local> exception sends it direct.
The dev server may refuse an unfamiliar name. Vite answers "Blocked request.
This host is not allowed", webpack-dev-server "Invalid Host header". Add the
name to server.allowedHosts in Vite or allowedHosts in
webpack-dev-server.
The computer's LAN address, such as http://192.168.1.20:3000. Find it
with ipconfig getifaddr en0 on macOS, ipconfig on Windows, hostname -I
on Linux.
By default a dev server answers only on 127.0.0.1 and cannot be reached at
the LAN address. To make it listen on all addresses, start Vite with
--host, webpack-dev-server with --host 0.0.0.0, Next.js with
-H 0.0.0.0.
Private addresses (192.168.*, 10.*) are often in the system exceptions as
well. So set the proxy in the browser itself, with the --proxy-server flag in
Chrome or manual configuration in Firefox.
System proxy exceptions
This is the list of addresses that programs using the system proxy reach directly. Where to find it:
- Windows: Settings → Network & Internet → Proxy → the exceptions field and the Don't use the proxy server for local (intranet) addresses box.
- macOS: System Settings → Network → the connection → Details → Proxies → Bypass proxy settings for these hosts & domains.
- Command-line tools take exceptions from the
NO_PROXYandno_proxyvariables. Removelocalhostand127.0.0.1from them.
Go programs that read the proxy from the environment
(http.ProxyFromEnvironment) never send localhost or 127.* through a
proxy, even with an empty NO_PROXY. Only a hosts-file name works for them.
A local server from a phone
On a phone, localhost means the phone, not your computer. Open the
computer's LAN address on the phone,
such as http://192.168.1.20:3000, with the dev server listening on all
addresses. How to send the phone's traffic to the proxy:
traffic from a phone.
See it on your own traffic
By default Solpuga listens on port 7070; change it under Settings →
Proxy. When it becomes the system proxy, it writes
exceptions for localhost, 127.0.0.1, *.local and private addresses
(10.*, 172.16–31.*, 192.168.*; on Windows also <local>). So a browser
on system settings sends both localhost and the computer's LAN address past
Solpuga. Open the server under a hosts-file name, or start Chrome with the
flags above, which point it straight at Solpuga.
By default Solpuga decrypts HTTPS only for listed hosts. To see the contents
of requests to a local HTTPS server, add its address under Settings →
SSL Proxying. Use localhost, 127.0.0.1, a hosts-file name or
host:port. Solpuga accepts such a server's self-signed certificate while
strict TLS validation is off, which is the default. Details:
Settings.
Related
- Proxy not working with a VPN, an antivirus or a corporate proxyA debugging proxy, a VPN, an antivirus that scans HTTPS and a corporate proxy all compete for the same traffic. How to find which one took it, and how to chain them.
- Why an HTTPS proxy does not see an app's trafficThe proxy is set up and the certificate is installed, yet the app's requests are missing or die in the TLS handshake. Six scenarios, with a network-level diagram of each and what it looks like in the proxy.
- How to see the traffic from an iPhone or an Android phonePhone and computer on one Wi-Fi, a proxy in the network settings, a root certificate with full trust. Four steps, and the five things that break them.