Configure HTTP/HTTPS proxy access

Updated at:
Copy as MD

Point the outbound requests of your client to the Egress Proxy Gateway (EPG) proxy address to route HTTP and HTTPS traffic through a unified Internet egress. EPG provides a fixed egress IP address, fine-grained access control by domain name or URL, and flexible access across VPCs, eliminating the O&M burden of a self-managed proxy cluster.

Differences between HTTP listeners and HTTPS listeners

When you create an EPG instance, both an HTTP listener and an HTTPS listener are created, for example, HTTP:1080 and HTTPS:443. The two listeners differ in whether the proxy channel between the client and EPG is encrypted. The HTTP listener provides a plaintext channel, and the HTTPS listener provides a TLS-encrypted channel.

Comparison

HTTP listener

HTTPS listener

Proxy channel encryption

Plaintext transmission. The security of the proxy channel relies on the internal network environment of the VPC.

TLS encryption. Also called an HTTPS proxy (Proxy over TLS), or TLS client access in this product.

Scenarios

The most common access method. In most scenarios, the internal network of the VPC is a trusted environment, so the proxy channel does not require additional encryption.

Zero trust scenarios that require the proxy channel itself to be encrypted for compliance.

Proxy address configuration

Set to http://<EPG domain name>:<HTTP listener port>. The HTTP listener port is 1080 by default.

Set to https://<EPG domain name>:<HTTPS listener port>. The HTTPS listener port is 443 by default.

Client requirements

No special requirements.

The client must support HTTPS proxies. Some earlier versions of tools or HTTP libraries do not. Verify client compatibility before you connect.

Important

TLS client access and TLS interception are two independent concepts. Do not confuse them. You can enable them separately, and they do not affect each other.

  • TLS client access: uses the HTTPS listener to encrypt the proxy communication between the client and EPG, which protects the proxy channel itself. It is commonly used in zero trust scenarios.

  • TLS interception: controls whether EPG decrypts the HTTPS traffic between the client and the destination server. When TLS interception is enabled, EPG acts as a proxy and uses a private CA certificate to decrypt the traffic into plaintext, which enables Layer 7 content control and auditing.

Prerequisites

  • You have created an EPG instance with an HTTP listener and an HTTPS listener, and you have created the default address pool.

  • The procedures in this topic use an Internet proxy as an example. You must bind at least one available elastic IP address (EIP) to each zone of the default address pool, so that the EPG instance can forward requests to the Internet.

  • You have deployed an application in the VPC to which the EPG instance belongs, and the application must access Internet services through the EPG proxy.

Configure proxy access

EPG works as an explicit proxy and does not support transparent traffic interception. The client must point its outbound requests to the EPG proxy address. After EPG completes policy control, it forwards the requests to the destination service. If you use EPG for the first time, see Quick start to get started.

Step 1: Obtain the proxy address

On the Basic Information tab of the instance details page, view the DNS domain name of the instance, in a format such as epg-xxx.cn-shanghai.epg.aliyuncs.com. This domain name is the proxy address that the client uses. When the instance is deployed in multiple zones, the domain name resolves to the proxy nodes in each zone.

Step 2: Configure proxy environment variables

This step uses the HTTP listener (plaintext proxy channel) as an example. Set both http_proxy and https_proxy to the address of the HTTP listener of EPG, for example, http://<your EPG domain name>:1080. The http and https in the variable names indicate the destination protocol (whether the destination is an HTTP or an HTTPS service), not the protocol of the proxy channel.

To encrypt the proxy channel between the client and EPG (zero trust scenarios), use the HTTPS listener instead and set the address to https://<your EPG domain name>:443. Make sure that the client supports HTTPS proxies (some earlier versions of tools or HTTP libraries do not).

Replace <your EPG domain name> with the DNS domain name of your EPG instance, in a format such as epg-xxx.cn-shanghai.epg.aliyuncs.com.

ECS access

The following example uses Alibaba Cloud Linux 4 (the default shell is bash).

The following commands write the proxy configuration to /etc/profile.d/epg-proxy.sh so that the configuration remains in effect across system restarts and new logon sessions.

sudo tee /etc/profile.d/epg-proxy.sh > /dev/null <<'EOF'
# The proxy port points to the HTTP listener port (such as 1080) for both http_proxy and https_proxy
export http_proxy=http://<your EPG domain name>:1080
export https_proxy=http://<your EPG domain name>:1080
# Internal networks, localhost, and Alibaba Cloud internal services bypass the proxy. For the meaning of each CIDR block, see "no_proxy recommendations" below.
export no_proxy=localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10,100.100.100.200,aliyuncs.com
# Both the lowercase and the uppercase variables are set for compatibility with different tools
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"
export NO_PROXY="$no_proxy"
EOF
# Apply the configuration to the current session immediately. New logon sessions load it automatically.
source /etc/profile.d/epg-proxy.sh

Container access (Docker/Kubernetes)

In container scenarios, we recommend that you inject the proxy environment variables through the image or the orchestration layer:

  • In a Dockerfile, declare the variables by using ENV, or pass the variables when you run docker run by using -e.

    # Docker: inject the proxy environment variables when you run the container (both the lowercase and the uppercase variables are set for compatibility with different tools)
    docker run \
      -e http_proxy=http://<your EPG domain name>:1080 \
      -e https_proxy=http://<your EPG domain name>:1080 \
      -e no_proxy=localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10,100.100.100.200,aliyuncs.com \
      -e HTTP_PROXY=http://<your EPG domain name>:1080 \
      -e HTTPS_PROXY=http://<your EPG domain name>:1080 \
      -e NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10,100.100.100.200,aliyuncs.com \
      your-image
  • In Kubernetes, configure the variables in the container env field of a pod or a Deployment. You can also manage the variables centrally by using a ConfigMap.

    # Kubernetes: inject the proxy environment variables in the container env field (both the lowercase and the uppercase variables are set for compatibility with different tools)
    spec:
      containers:
        - name: your-app
          image: your-image
          env:
            - name: http_proxy
              value: "http://<your EPG domain name>:1080"
            - name: https_proxy
              value: "http://<your EPG domain name>:1080"
            - name: no_proxy
              value: "localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10,100.100.100.200,aliyuncs.com"
            - name: HTTP_PROXY
              value: "http://<your EPG domain name>:1080"
            - name: HTTPS_PROXY
              value: "http://<your EPG domain name>:1080"
            - name: NO_PROXY
              value: "localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10,100.100.100.200,aliyuncs.com"
Important

The protocol prefix and the port of the proxy address must match. Use http://<your EPG domain name>:1080 for the HTTP listener and https://<your EPG domain name>:443 for the HTTPS listener. If the protocol prefix does not match the port, the proxy connection fails. For example, the Proxy CONNECT aborted error occurs.

Step 3: Verify that the proxy takes effect

Send a test request to verify that the outbound traffic of the client is forwarded through the EPG proxy.

# Verify HTTP access to the Internet. An HTTP status code of 301 indicates success.
curl -I --max-time 15 http://help.aliyun.com

# Verify HTTPS access to the Internet. An HTTP status code of 302 indicates success.
curl -I --max-time 15 https://help.aliyun.com

# The following example uses an ECS instance in the Shanghai region to verify that no_proxy takes effect. Alibaba Cloud internal services must be accessed directly. An XML error response indicates that the direct connection succeeds.
curl --max-time 15 https://ecs.cn-shanghai.aliyuncs.com

Configure the proxy in code

In addition to environment variables, you can specify the proxy address directly in your application code. This method does not affect other processes on the same machine, and applies to scenarios that require fine-grained control over the scope of the proxy. As with the environment variable method, both the http and the https proxy in the code point to the HTTP proxy port of EPG, such as 1080. The following example uses Python:

import requests

proxies = {
    'http': 'http://<your EPG domain name>:1080',
    'https': 'http://<your EPG domain name>:1080',
}
response = requests.get('https://help.aliyun.com', proxies=proxies)

Because the proxy takes effect only in this code, the curl verification method that is based on environment variables no longer applies. A successful response to the request in your code indicates that the proxy takes effect. To make internal network and localhost addresses bypass the proxy, note that libraries such as requests still read the no_proxy environment variable. You can use this variable to exclude the addresses.

Remove the proxy configuration

ECS

  • Disable the proxy temporarily (current session only): Clear the proxy environment variables in the current shell. New logon sessions load the variables again.

    unset http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
  • Remove the proxy permanently: Delete the persistence script and clear the environment variables in the current session, or log on again. New sessions no longer load the proxy configuration.

    sudo rm /etc/profile.d/epg-proxy.sh
    unset http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY

Containers/Kubernetes

Remove the proxy environment variables that the image or the orchestration layer injects, including http_proxy, https_proxy, and no_proxy, together with their uppercase counterparts. The change takes effect after you rebuild the image or redeploy the workload.

Code

Stop passing the proxies parameter when you send requests to restore direct connections. If you previously relied on environment variables such as no_proxy to control the proxy scope, clear them as well.

no_proxy recommendations

no_proxy specifies the addresses that the client accesses directly, without going through the EPG proxy. This prevents traffic to localhost, internal networks, and Alibaba Cloud internal services from being proxied by mistake. The following list describes the common types. Configure them based on your actual proxy scope:

  • Localhost addresses: localhost and 127.0.0.1

  • Private internal CIDR blocks: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16

  • Alibaba Cloud reserved CIDR block: 100.64.0.0/10 (the shared address range that Alibaba Cloud internal services use)

  • Alibaba Cloud metadata service: 100.100.100.200 (if the traffic is forwarded through the proxy, instance metadata and RAM temporary credentials fail to be obtained)

  • Alibaba Cloud internal services: aliyuncs.com (including its subdomains, such as ecs.cn-shanghai.aliyuncs.com. Note that this is not aliyun.com.)

Different clients use different matching rules for no_proxy, such as whether subdomains and CIDR blocks are supported. Follow the behavior of the client that you use.

Usage notes

  • EPG supports only the HTTP proxy protocol. When you configure the proxy, use a proxy address that starts with http:// or https://. SOCKS proxy methods such as socks5:// are not supported.

Quotas

To request a quota increase, contact your business manager.

Quota item

Default value

Adjustable upper limit

Number of listener ports per instance

2

50