I have this on my machine:

$ cat /etc/profile.d/proxy.sh 
export http_proxy=
export https_proxy=

That works great, until I need to use an HTTP interface with an application on the localhost.

$ wget localhost
--2023-03-02 06:54:52--  http://localhost/
Connecting to connected.
Proxy request sent, awaiting response... 503 Service Unavailable
2023-03-02 06:54:52 ERROR 503: Service Unavailable.

$ wget
--2023-03-02 06:55:20--
Connecting to connected.
Proxy request sent, awaiting response... 403 Forbidden
2023-03-02 06:55:20 ERROR 403: Forbidden.

Is there a way to prevent localhost and requests from being forwarded to the proxy?


This machine isn't connected directly to the internet. It has no gateway or default route. But it is on a LAN with a proxy machine ( that has a proxy server installed (port 3128) and has an internet connection.

$ ip addr
1: lo: ...
    inet scope host lo
2: eno1: ...
    altname enp24s0f0
    inet brd scope global eno1

$ ip route dev eno1 proto kernel scope link src

$ cat /etc/hosts   localhost

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eno1
iface eno1 inet static

1 Answer 1


From wget man page:


Wget supports proxies for both HTTP and FTP retrievals. The standard way to specify proxy location, which Wget recognizes, is using the following environment variables:

http_proxy and https_proxy

If set, the http_proxy and https_proxy variables should contain the URLs of the proxies for HTTP and HTTPS connections respectively.


This variable should contain the URL of the proxy for FTP connections. It is quite common that http_proxy and ftp_proxy are set to the same URL.


This variable should contain a comma-separated list of domain extensions proxy should not be used for. For instance, if the value of no_proxy is .mit.edu, proxy will not be used to retrieve documents from MIT.

So, you should change your /etc/profile.d/proxy.sh to:

export http_proxy=
export https_proxy=
export no_proxy=",localhost"

If you have a GUI web browser that does not use the *_proxy environment variables, then you could create a proxy autoconfiguration file, name the file proxy.pac, have your local HTTP server provide it with MIME type application/x-ns-proxy-autoconfig.

Then configure your desktop environment and/or web browser(s) to use that autoconfiguration file, by specifying a proxy autoconfiguration URL like http://localhost/some/where/proxy.pac (or maybe even file:///some/location/proxy.pac) in the proxy settings of the desktop environment or web browser.

In your case, the contents of the file could be:

function FindProxyForURL(url, host)
    // If not a http: or https: URL, go direct always.
    if (!shExpMatch(url,"http*") {
        return "DIRECT";

    // If the destination is:
    // - any 127.*.*.* address
    // - or anything like "localhost*"
    // - or the web browser host's own IP address
    // Then go direct to destination.

    else if (shExpMatch(host, "127.*")
        || shExpMatch(host, "localhost*")
        || host == myIpAddress()) {
        return "DIRECT";
    else {
        // Otherwise, use the proxy specified here.
        return "PROXY";
  • Fantastic! I didn't look into man wget because I've reproduced the problem with curl and python3-urllib3, so I figured it was system-wide and not application-specific. I didn't realize that these applications just all happen to have code to handle these variables.
    – Stewart
    Commented Mar 2, 2023 at 16:09
  • 1
    One might say that those environment variables might be the closest thing to an universal standard for configuring a HTTP(S) proxy we have for unix-like operating systems. The various desktop environments can have their own system-wide and per-user proxy settings, but those may not always apply to command-line programs or services executed outside a user's login session.
    – telcoM
    Commented Mar 2, 2023 at 23:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .