---
title: "Why Is the HTTP_PROXY Variable Not Working? 8 Causes"
description: "HTTP_PROXY is usually skipped because of a wrong name, a NO_PROXY entry that covers the target or a library that ignores the environment. 8 causes and tests."
url: https://proxynet.io/blog/http-proxy-env-not-applied
date: 2026-12-01
author: "Acar Diveroli"
category: "Tutorial"
lang: en
---

# Why Is the HTTP_PROXY Variable Not Working? 8 Causes

`HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` are environment variables that give programs a proxy address without touching the code. Every tool reads them by its own rules: it looks at the case of the name, the scheme of the target and where the process got its environment from. When the variable is not read, most tools raise no error. The request quietly leaves from your own IP. This post covers the 8 reasons the variable gets skipped, a one-line test for each and a table that leads from symptom to cause.

> **Note: Short answer**
>
> The variable is usually skipped because it has the wrong name, `NO_PROXY` covers the target, it never reaches the child process or the library ignores the environment. Set `HTTPS_PROXY` for HTTPS sites and look for the `Uses proxy env variable` line in `curl -v` output.

## Variable name and target

A tool picks the variable by the scheme of the target. A wrong name is more common than a wrong value.

### 1. HTTPS target, only HTTP_PROXY set

A request to a URL starting with `https://` looks at `HTTPS_PROXY`, not `HTTP_PROXY`. In our test, with only `http_proxy` set, curl and Requests went straight to the HTTPS target. Not a single line reached our test proxy. The variable name refers to the target, the scheme in the value to the proxy protocol. The syntax rules are in [how to read a proxy URL](/blog/proxy-endpoint-format).

```bash
export HTTP_PROXY="http://user:pass@pr.proxynet.io:8000"
export HTTPS_PROXY="$HTTP_PROXY"
```

With environment proxies turned on (cause 7), Node's `fetch` broke this rule. Without `HTTPS_PROXY` it used the `HTTP_PROXY` value, while the `https` module did not. Set both for consistent results across tools. HTTPS traffic passes the proxy through a `CONNECT` tunnel, and the [HTTPS Proxy](https://proxynet.io/https-proxy) page explains that flow.

Test: `curl -sv -o /dev/null https://httpbin.org/ip 2>&1 | grep "proxy env"`. If the line is empty, curl picked up no variable.

### 2. Upper and lower case

curl reads `http_proxy` only in lowercase. `HTTPS_PROXY`, `NO_PROXY` and `ALL_PROXY` are read in both spellings, and if both exist, the lowercase one wins. The reason is CGI. A web server turns the client's `Proxy:` header into a variable named `HTTP_PROXY`. That lets an outsider choose the proxy of a script on the server. The flaw was announced as httpoxy in 2016, while curl has ignored the uppercase name since 2001.

On Linux and macOS, if you set only `HTTP_PROXY` and call a plain HTTP URL with curl, the request goes out directly. Windows does not distinguish case in variable names. In our test, `HTTP_PROXY` worked fine in Windows curl. Python's `urllib` module and Node read both spellings.

Test: `env | grep -i _proxy`. If the two spellings of a name carry different values, make them equal.

## NO_PROXY matching

Each name in the `NO_PROXY` list matches the target itself or a domain suffix. A matching request never touches the proxy.

### 3. NO_PROXY covers the target

A lone `*` takes every target out of the proxy. A leftover `NO_PROXY=*` in a Docker image or on a company machine sends all traffic directly. A broad suffix does the same. In our test we tried these values for the target `test.invalid`:

| NO_PROXY value | curl | Requests | Node fetch |
|---|---|---|---|
| `invalid` | ✓ | ✓ | ✓ |
| `.invalid` | ✓ | ✓ | ✓ |
| `*` | ✓ | ✓ | ✓ |
| `*.invalid` | ✗ | ✗ | ✓ |
| `est.invalid` | ✗ | ✗ | ✗ |

A ✓ means the request bypassed the proxy. A partial name matched in no tool. Wildcard handling varied by tool. A space after the comma caused no problem in any of the three.

Test: `python -c "import requests; print(requests.utils.get_environ_proxies('https://httpbin.org/ip'))"`. If the output is `{}`, either the variable is missing or `NO_PROXY` covers the target.

## Processes the variable never reaches

A program copies its environment once, from the process that starts it. Later changes do not reach a running program.

### 4. A variable that never reaches the child process

In Bash, an assignment without `export` is only a variable of the shell itself. In our test, curl run after a `HTTPS_PROXY=...` line did not see the variable. With `export` added, it did. On Windows, three commands carry three different scopes:

| Command | Scope | When it applies |
|---|---|---|
| `set` (cmd) | This window | Immediately, for programs started from it |
| `$env:` (PowerShell) | This session | Immediately, for programs started from it |
| `setx` | User environment | Only in newly opened windows |

`setx` writes the value to the registry and leaves the open window alone. The Microsoft docs also note a 1024-character limit. A terminal, editor or IDE that stays open keeps running with the old environment, so restart it.

cmd has one more trap. Write `set HTTPS_PROXY=http://... && curl ...` and the space before `&&` becomes part of the value. In our test, curl failed with `(5) Unsupported proxy syntax` and Requests with `InvalidURL`. Quote the value: `set "HTTPS_PROXY=http://user:pass@pr.proxynet.io:8000"`.

Test: in Bash, `bash -c 'echo ${HTTPS_PROXY:-unset}'`. In PowerShell, `$env:HTTPS_PROXY` shows the session value and `[Environment]::GetEnvironmentVariable("HTTPS_PROXY","User")` the value written with `setx`.

### 5. sudo resets the environment

sudo's `env_reset` option is on by default. The command starts with a short list such as `PATH`, `HOME` and `USER`, plus the variables named in `env_keep`. If the proxy variables are not on that list, `sudo curl` and `sudo pip` go out directly.

There are three fixes. `sudo -E` asks to keep the environment, but the sudoers policy can refuse it. The permanent fix is a `Defaults env_keep += "http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY"` line added with `visudo`. The third is to pass the proxy to the command explicitly. The config files of tools like apt are covered in [Linux proxy settings](/blog/linux-proxy-settings).

Test: `sudo env | grep -i _proxy`. If the output is empty, sudo does not carry the variables.

### 6. Services, cron and containers

Background processes are not born from your login shell. They do not read your `~/.bashrc`.

- **A systemd service** takes its environment from the `Environment=` lines in its unit file.
- **cron** jobs start with a short environment. Define the variables at the top of the crontab or inside the script.
- **A Docker container** only sees variables passed with `-e`, `--env-file` or set by `ENV` in the image.
- **A Windows service** running under another account does not see your user variables. A value written with `setx` without `/m` goes only to your account.

Test: `systemctl show <service> -p Environment`, `docker exec <container> env | grep -i proxy`. For cron, add a temporary `* * * * * env > /tmp/cron-env.txt` line, read the file, then delete the line.

## Libraries that ignore the environment

Some libraries read the variable only when you ask them to. Here the problem is in the code, not the environment.

### 7. Node fetch and the http modules

Node's built-in `fetch` and the `http`/`https` modules do not read proxy variables by default. In our test with Node 24.22.2, `fetch` failed with `ENOTFOUND` while `HTTPS_PROXY` was set. The request skipped the proxy and tried to resolve the target name itself. With `NODE_USE_ENV_PROXY=1` or `--use-env-proxy`, the same request opened a `CONNECT` tunnel at the proxy.

```bash
NODE_USE_ENV_PROXY=1 \
HTTPS_PROXY="http://user:pass@pr.proxynet.io:8000" \
node app.js
```

According to the Node docs, `NODE_USE_ENV_PROXY` arrived in v24.0.0 and v22.21.0. The `--use-env-proxy` flag and `http` module support were added in v24.5.0. The feature is still marked as under active development. On an older version, pass the proxy explicitly in code.

Test: `node --use-env-proxy -e "fetch('https://httpbin.org/ip').then(r=>r.text()).then(console.log)"`. Compare the IP with a run without the flag.

### 8. trust_env in Python

In Python HTTP libraries, reading the environment depends on the `trust_env` flag. The defaults differ: `False` in aiohttp, `True` in Requests and HTTPX. In our test, aiohttp 3.13.3 with a default session went direct and raised `ClientConnectorDNSError`. With `trust_env=True`, the same request went through the proxy. The full setup is in [using a proxy with aiohttp](/blog/aiohttp-proxy).

Requests works the other way round. If the code sets `session.trust_env = False` somewhere, that session ignores the variables. In our test, such a `Session` went direct. The line often sits inside a library, out of sight.

Test: run `grep -rn "trust_env" .` in the project folder. `python -c "import aiohttp, inspect; print(inspect.signature(aiohttp.ClientSession).parameters['trust_env'].default)"` shows the aiohttp default.

## From symptom to cause

A DNS error on the target name while a proxy is set means the request went direct. With an HTTP proxy, the proxy resolves the target name, not the client. Every message below came up in our test.

| Symptom | Meaning | Cause to check |
|---|---|---|
| curl `(6) Could not resolve host` | Went direct | 1-6 |
| Node `ENOTFOUND` | Went direct | 7 |
| aiohttp `ClientConnectorDNSError` | Went direct | 8 |
| curl `(5) Unsupported proxy syntax` | Broken value | Trailing space, password |
| curl `(7) CONNECT tunnel failed` | Reached the proxy | Problem on the proxy side |

A direct connection to a real site usually raises no error, and the page still loads. That is why the real test is the exit IP. Run the same command with and without the variable. If the two IPs match, the variable is being skipped.

## How we tested

We ran the tests on December 1, 2026, on Windows 11. We used curl 8.22.0 (Windows), Python 3.13.17, Requests 2.34.2, aiohttp 3.13.3, HTTPX 0.28.1 and Node 24.22.2 (undici 7.30.1). We ran the `export` test in Git Bash and the `set` and `$env:` tests in cmd and PowerShell 5.1. On `127.0.0.1` we ran a proxy that logged the first line of every incoming request. The target was `test.invalid`, a name that never resolves. A request through the proxy left a line in the log, a direct request failed with a DNS error. Each scenario ran in a fresh process with a clean environment. We did not test sudo, cron, systemd or case sensitivity on Linux; those parts rely on the official docs.

## The bottom line

Set both schemes and both spellings, keep the `NO_PROXY` list short and choose explicitly in code whether the library reads the environment. Above all, confirm the proxy works by its exit IP, not by the absence of errors. Once the settings are ready, you can make the first attempt with [Residential Proxy](https://proxynet.io/residential-proxy).

## Sources

- [curl man page, ENVIRONMENT section: curl.se](https://curl.se/docs/manpage.html)
- [Node.js docs, Built-in Proxy Support: nodejs.org](https://nodejs.org/api/http.html#built-in-proxy-support)
- [aiohttp docs, ClientSession `trust_env`: docs.aiohttp.org](https://docs.aiohttp.org/en/stable/client_reference.html)
- [sudoers manual, Command environment: sudo.ws](https://www.sudo.ws/docs/man/sudoers.man/)
- [Microsoft docs, setx: learn.microsoft.com](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/setx)

## Frequently asked questions

### How do I know if the proxy environment variable is being read?

In two steps. First, look for the `Uses proxy env variable` line in `curl -v` output. That line shows curl picked up the variable. Then send a request from your actual program to an IP echo service and compare the address with a run without the variable. If the two IPs match, the program is skipping the variable. No error on its own is not proof.

### Should I write HTTP_PROXY or http_proxy?

Write both with the same value. curl reads `http_proxy` only in lowercase, because in a CGI environment the uppercase name can be derived from a client header. Requests, `urllib` and Node read both spellings, and when both exist the lowercase one usually wins. Windows ignores case, Linux and macOS do not. Two spellings carrying different values is the hardest bug to find.

### Does Node.js fetch read the HTTPS_PROXY variable?

Not by default. Node's built-in `fetch` reads proxy variables only with the `NODE_USE_ENV_PROXY=1` environment variable or the `--use-env-proxy` flag. In our test, Node 24.22.2 sent the request directly without the flag and opened a `CONNECT` tunnel at the proxy with it. According to the docs, support arrived in v24.0.0 and v22.21.0. On older versions, pass the proxy in code.

### Why doesn't the proxy I set with setx work?

`setx` writes the value to the registry, and only windows opened afterwards get it. The window you ran the command in, open editors and running programs keep the old environment. Close and reopen the terminal and the IDE. For a value that takes effect immediately, use `$env:HTTPS_PROXY` in PowerShell or a quoted `set "HTTPS_PROXY=..."` in cmd. A `setx` value also has a 1024-character limit.

### Why does a command run with sudo ignore the proxy?

Because sudo resets the environment by default. With the `env_reset` option on, the command starts with only a short list of variables and those named in `env_keep`. If the proxy variables are not on that list, the command goes out directly. `sudo -E` asks to keep the environment, but the policy may not allow it. The permanent fix is to add the proxy variables to `env_keep` with `visudo`.

### Can I use wildcards in the NO_PROXY list?

Only a lone `*` works in every tool, and it takes all targets out of the proxy. `*.example.com` behaves differently from tool to tool. In our test, Node matched it, curl and Requests did not. The safe forms are `.example.com` or `example.com`. In our test, both covered subdomains in all three tools. A partial name such as `ample.com` matched in none.
