http_proxy, https_proxy and no_proxy: Setup on Linux, Windows and Docker
Updated:
The HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables tell command-line tools and programming libraries which proxy to use and which addresses to reach directly. The standard syntax is http://user:pass@ip:port for both proxy variables, including HTTPS_PROXY, while NO_PROXY is a comma-separated list of domains or addresses. Set both the upper-case and lower-case forms, because tools differ in which one they read. This guide covers temporary and permanent setup on Linux, Windows and Docker, the cases where environment variables have no effect, and how to verify.
The three variables
The most common mistake is HTTPS_PROXY=https://.... The scheme in the value describes how to connect to the proxy itself, not to the website. A standard HTTP/HTTPS proxy accepts http:// connections, so both values start with http://. VinaProxy proxies are delivered as ip:port:user:pass; convert them to URLs with the proxy format converter if needed.
| Variable | Example value | Effect |
|---|---|---|
HTTP_PROXY / http_proxy | http://user:pass@ip:port | Proxy for http:// requests |
HTTPS_PROXY / https_proxy | http://user:pass@ip:port | Proxy for https:// requests; tools open a CONNECT tunnel through the HTTP proxy |
NO_PROXY / no_proxy | localhost,127.0.0.1,.internal.local | Addresses reached directly, bypassing the proxy |
Upper case or lower case?
There is no single standard; each tool decides. For example, curl reads only lower-case http_proxy for HTTP requests, for security reasons, but accepts HTTPS_PROXY in either case. Python requests reads both. Other tools prefer one form and ignore the other. The safe approach is to set both forms to the same value.
If the password contains characters such as @, :, # or %, URL-encode it (@ becomes %40), or tools will split the string wrongly and you will get 407 Proxy Authentication Required.
Linux and macOS
- Temporary, current terminal only:
export http_proxy=http://user:pass@ip:port, thenexport https_proxy=$http_proxy,export HTTP_PROXY=$http_proxy,export HTTPS_PROXY=$http_proxy. - Bypass internal addresses:
export no_proxy=localhost,127.0.0.1,.internal.localandexport NO_PROXY=$no_proxy. - Permanent for your user: add those
exportlines to~/.bashrcor~/.zshrcand open a new terminal. - System-wide on Ubuntu: add
http_proxy=http://user:pass@ip:port(withoutexport) to/etc/environment, then log out and back in. Details are in the Ubuntu proxy setup guide. sudostrips most environment variables by default. Usesudo -E commandor configureenv_keepif commands run with sudo also need the proxy.aptdoes not reliably pick up environment variables under sudo; create/etc/apt/apt.conf.d/95proxycontainingAcquire::http::Proxy "http://user:pass@ip:port/";and a matching line forAcquire::https::Proxy.- To remove:
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXYand delete the lines you added to config files.
Windows
- CMD, current window only:
set HTTP_PROXY=http://user:pass@ip:portandset HTTPS_PROXY=http://user:pass@ip:port. - PowerShell, current session:
$env:HTTP_PROXY = 'http://user:pass@ip:port'and$env:HTTPS_PROXY = 'http://user:pass@ip:port'. - Permanent for your user:
setx HTTP_PROXY http://user:pass@ip:portandsetx HTTPS_PROXY http://user:pass@ip:port. They apply only to windows and apps opened afterwards. - Or use the UI: System Properties, Environment Variables, and add them under User variables.
- Important: environment variables are separate from the Windows system proxy setting. Browsers and many GUI apps use the system setting, while curl, git, pip and Python read environment variables. The system setting is covered in the Windows proxy setup guide.
Docker: three different places
With Docker, the proxy may be needed in three places, and setting it in the wrong one is a common reason for "I set the proxy and it still fails".
- The Docker daemon pulling images: the daemon does not see your terminal's variables. Create
/etc/systemd/system/docker.service.d/http-proxy.confwith a[Service]section andEnvironment="HTTP_PROXY=http://user:pass@ip:port" "HTTPS_PROXY=http://user:pass@ip:port" "NO_PROXY=localhost,127.0.0.1", then runsudo systemctl daemon-reloadandsudo systemctl restart docker. - Containers and builds: add a
proxiesblock to~/.docker/config.jsonwithhttpProxy,httpsProxyandnoProxy; the Docker CLI then passes them into new containers and builds. - Per command:
docker run -e HTTPS_PROXY=http://user:pass@ip:port imageordocker build --build-arg HTTPS_PROXY=http://user:pass@ip:port .. - Inside a container,
localhostis the container itself. If a proxy runs on the host, do not use127.0.0.1in the proxy value. The full walkthrough is in the Docker proxy setup guide.
Writing NO_PROXY correctly
- Comma-separated, no spaces:
localhost,127.0.0.1,.internal.local,api.company.com. - A leading dot as in
.internal.localusually matches all subdomains; many tools treatinternal.localthe same way. - CIDR ranges such as
10.0.0.0/8are supported by some tools and not others. To be safe, list addresses or use hostnames. - Always include
localhostand127.0.0.1so local services do not loop through the proxy. - Add internal services, private package registries and database hosts to avoid confusing connection errors.
Verify, troubleshoot and stay safe
- List current values:
env | grep -i proxyon Linux,Get-ChildItem Env: | Where-Object Name -like '*proxy*'in PowerShell. - Check the exit IP with
curl -s https://httpbin.org/ipand compare it with the proxy IP, or open what is my IP from that machine. Add-vto confirm curl really connects through the proxy. See the curl proxy guide. - Not every program reads environment variables. Some Node.js libraries and apps that manage their own networking need explicit proxy settings, as in the Node.js axios proxy setup.
- Variables holding proxy passwords can leak through shell history, logs or process listings. Do not commit config files with passwords to Git; if one leaks, change the proxy password in the dashboard.
- To remove proxy settings entirely, follow how to turn off a proxy.
Frequently asked questions
Should HTTPS_PROXY start with http:// or https://?
Almost always http://. The scheme describes the connection to the proxy, and a standard HTTP/HTTPS proxy accepts HTTP connections and tunnels HTTPS traffic.
Why does curl ignore my HTTP_PROXY?
curl reads only lower-case http_proxy for HTTP requests. Set the lower-case form too, or pass the proxy directly with -x.
Do environment variables make my browser use the proxy?
Usually not on Windows and macOS, where browsers use the system proxy setting. Environment variables mainly affect command-line tools and libraries.
Why does docker pull still fail after exporting the proxy?
The Docker daemon runs as a separate service and does not see your terminal's variables. Configure the proxy for the docker service through systemd and restart it.
Can I use these proxies through ALL_PROXY as SOCKS?
VinaProxy proxies are HTTP/HTTPS with username and password authentication. Use HTTP_PROXY and HTTPS_PROXY as shown above.
HTTP/HTTPS proxies ready for your servers
Private IPv4 in 7 countries and static ISP in Vietnam and the US. Username and password auth, ip:port:user:pass format, unlimited bandwidth.
See pricing