HTTP_PROXY, HTTPS_PROXY and NO_PROXY Explained

A proxy environment variable can change the route your application uses. Compare direct and proxied requests and check how your client interprets the destination scheme, variable names and bypass list.

Rear of a server rack with orange and teal Ethernet cables and a network switch

Which proxy variable controls an HTTPS request?

The scheme of the destination URL usually selects the proxy variable. In cURL, an http:// destination uses http_proxy and an https:// destination uses https_proxy or HTTPS_PROXY. The value then describes how the client reaches the proxy. The setting HTTPS_PROXY=http://gateway.example:8080 is valid. For an HTTPS destination, cURL connects to that HTTP proxy, requests a tunnel with CONNECT and then negotiates TLS with the destination through the tunnel. cURL proxy environment variables.

When the proxy endpoint itself accepts TLS, its value starts with https://. The client establishes TLS with that proxy before it sends CONNECT. Use the scheme your provider assigned to the proxy port. A mismatch can surface as a certificate or handshake error even when the destination site is healthy. ALL_PROXY is cURL’s fallback when the applicable scheme has no proxy configured. A scheme-specific setting wins over that fallback. Compare HTTP, HTTPS and SOCKS5 proxies.

How cURL applies NO_PROXY and lowercase variables

NO_PROXY and no_proxy list destinations that should use a direct route. For cURL, the list contains comma-separated host or domain entries. Use a destination hostname such as testmyproxies.com without its scheme or path. The entry refers to the target, so putting the proxy gateway’s own hostname in the list does not exempt traffic sent through that gateway. A single asterisk matches every destination. cURL 7.86.0 and later also support CIDR entries. Use exact destination hosts first when debugging. Matching rules for suffixes, ports and networks vary by client.

On systems with case-sensitive environment names, cURL prefers lowercase spellings when both cases are set. For HTTP destinations it recognizes lowercase http_proxy only. CGI servers can derive an uppercase HTTP_PROXY variable from an incoming request header, which makes the uppercase spelling unsafe to interpret as trusted HTTP proxy configuration. Windows treats environment variable names without case distinctions, so HTTPS_PROXY and https_proxy refer to the same entry in PowerShell on Windows. The practical choice for examples shared across platforms is one spelling per variable. cURL environment reference.

Test the proxy environment with cURL

Use the endpoint and routes your network administrator has approved. In Bash or another compatible Unix shell, this example uses a subshell so the settings end with the test. Replace gateway.example:8080 with your HTTP proxy’s address. The first request uses the proxy because the listed exclusion does not match the endpoint. The second sets an exclusion for the same destination and tests direct access. Omit the second request if this destination must always use the managed proxy.

(
  unset HTTPS_PROXY NO_PROXY ALL_PROXY all_proxy
  export https_proxy=http://gateway.example:8080
  export no_proxy=never-used.example
  curl --disable -sS --max-time 15 \
    -w "\nconnect=%{http_connect} destination=%{response_code}\n" \
    https://testmyproxies.com/api/my-ip

  export no_proxy=testmyproxies.com
  curl --disable -sS --max-time 15 \
    -w "\nconnect=%{http_connect} destination=%{response_code}\n" \
    https://testmyproxies.com/api/my-ip
)

For Windows PowerShell, use a temporary terminal. Set the environment for the first request as shown below. For an authorized direct comparison, set $env:no_proxy = 'testmyproxies.com' and repeat the same cURL command. Close the temporary terminal to discard the changes.

$env:https_proxy = 'http://gateway.example:8080'
$env:no_proxy = 'never-used.example'
curl.exe --disable -sS --max-time 15 -w "\nconnect=%{http_connect} destination=%{response_code}\n" https://testmyproxies.com/api/my-ip

An ordinary successful HTTP tunnel gives connect=200. A successful direct request has connect=000 because there was no CONNECT exchange. Expect destination=200 and a JSON ip field for either successful request. Compare that field with the exit IP your provider reports. If the two IPs match, the CONNECT status still shows whether the example used a tunnel. If both statuses are zero, use cURL’s error message to check whether the request got past DNS, the socket connection or TLS. Other cURL proxy checks.

Check whether an exclusion applies to your exact URL

Suppose an application should contact an approved internal status service directly at https://status.dev.example/health. A cURL exclusion for status.dev.example applies to that hostname. If the caller follows a redirect to a new hostname, cURL evaluates the next destination separately. Check the original and final destinations before expanding an exclusion. For example, changing a single host entry to a whole domain can route other services directly as well. If the hostname is correct but the application still uses the proxy, look for a different client matching rule or a value set on the service process.

Why Python Requests and Go can choose different routes

Python Requests uses the environment by default, with uppercase and lowercase proxy variables supported. An environment proxy can take precedence over a proxy saved on Session.proxies. If your program should use a specific proxy for a request, pass an explicit proxies mapping to that request. If your program should follow deployment settings, configure the environment of the process that runs it and verify an allowed test URL there. Pay particular attention to cases where your app supplies a proxy mapping and you also expect an environment exclusion. Requests proxy configuration. Python Requests configuration examples.

In Go, the standard http.DefaultTransport uses http.ProxyFromEnvironment. Its current environment reader checks uppercase names first, then lowercase, and reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY. It has no ALL_PROXY fallback. The implementation skips localhost and literal loopback addresses. A NO_PROXY entry such as .example.com matches subdomains in Go, while example.com also matches the apex. A custom http.Transport can have a different proxy function. For a test with new environment settings, start a fresh process because the standard function caches the configuration after its first use. Go net/http proxy documentation. Go proxy matching source.

Check where Docker and services get their variables

A shell export affects that shell’s child processes. An already-running service or container may have been started with different proxy values. An image build, an image pull and an HTTP request from an application inside a container can use different configuration too. Check which process owns the failed connection and verify its proxy settings there. When logging your findings, share variable names and sanitized endpoints. Full values can contain usernames or passwords. Docker CLI and container proxy configuration. Why a proxy works on the host but fails in Docker.

All proxy testing guides · Open the proxy tester