There are several methods to configure an application to use an egress proxy, including setting environment variables, modifying configuration files, using command-line arguments, and configuring network devices. Each method offers different benefits and is suitable for various scenarios.

Using Environment Variables

Environment variables are a flexible and widely-supported method for configuring proxy settings. Most programming languages and frameworks support setting proxy configurations via environment variables, making this a versatile solution.

Here are some common libraries and tools that support environment variables for proxy settings:

  • Python: requests, urllib, http.client

  • Java: HttpClient, Apache HttpClient

  • Node.js: http, https, axios

  • Go: http, net/http

  • Ruby: net/http, open-uri

  • cURL

For example, in a Dockerfile, you can set environment variables to ensure that the application uses the proxy during its runtime:

ENV http_proxy=
ENV https_proxy=

Alternatively, you can set environment variables in your shell before starting the application:

export http_proxy=
export https_proxy=

Configuration Files

Some applications allow you to specify proxy settings directly in their configuration files. This method can be particularly useful for applications with extensive configuration options and for maintaining consistency across different environments.

For instance, in Java applications, you can configure proxy settings in a properties file:

In Python applications, you can use a configuration file to set proxy settings:

import requests
proxies = {
    "http": "",
    "https": "",
response = requests.get('', proxies=proxies)

Command-Line Arguments

For some applications and tools, you can specify proxy settings directly through command-line arguments. This method is useful for temporary configurations and quick tests.

For example, with cURL, you can use command-line options to specify the proxy:

curl -x

In Java, you can pass proxy settings as JVM arguments:

java -Dhttp.proxyPort=10080 -Dhttps.proxyPort=10443 -jar app.jar

Network Configuration

At the network level, administrators can configure iptables, routing tables, routers, firewalls, or load balancers to route traffic through an egress proxy. This method ensures that all traffic from a network segment is proxied without needing to configure individual applications.

For example, you can set up firewall rules to redirect outbound traffic to a proxy server or configure the load balancer to route traffic through a proxy.

Last updated