Reverse Proxy to Upstream

Reverse proxy is one of the core functions of the OpenResty Edge. This document will provide detailed instructions on how to configure reverse proxy rules in Edge Admin.

Configuration Steps

1. Access Page Rules Configuration

First, navigate to the Page Rules page, where you can add gateway reverse proxy rules to upstream servers.

Click the New Rule button to start configuration.

2. Enable Proxy Module

The Proxy module in rule configuration is disabled by default. You need to click to expand this module first.

3. Configure Upstream Servers

3.1 Create New Upstream

If you haven’t added any upstream servers yet, you can choose to create a new upstream:

3.2 Upstream Configuration Parameters

Upstream servers support the following configuration options:

Basic Configuration

  • Name: Identifier name for the upstream
  • Protocol: Supports HTTP or HTTPS
  • Health Check: Configure active health checks for the upstream

Advanced Configuration

  • Use Proxy Hostname: Use the upstream domain name as the proxy hostname

    Note: When this option is enabled, you can only input one upstream server with a domain name as the address, and only one upstream can be selected in the proxy rule

Upstream Server List

An upstream can contain multiple upstream servers, with support for configuring different weights for different servers (requests are distributed according to weight).

Upstream server addresses support the following formats:

  1. IP Address: Direct use of IP addresses
  2. Domain Name: The gateway server will use the resolver configured in the local /etc/resolv.conf or the DNS resolver configured globally
  3. Dynamic Host Field: Use the Host field domain name from the proxied request (dynamic address, related to specific requests, rarely used)

4. Multiple Upstream Configuration and Weight Distribution

4.1 Multiple Upstream Weight Mechanism

The system supports using multiple upstreams simultaneously, with configurable weights for each upstream. The weight distribution mechanism works as follows:

  1. First-level Distribution: Requests are first distributed according to weights between upstreams
  2. Second-level Distribution: After being assigned to a specific upstream, requests are then distributed according to weights between nodes within that upstream

4.2 Canary Deployment Example

For example, you can add a canary upstream:

And a production upstream:

Allocate 10% of request traffic to the canary upstream and 90% to the production upstream:

5. Configure Matching Conditions

You can also configure different origin strategies based on request information. For example, specific configuration for v2 version APIs:

Configuration Complete

Following the above steps, a complete reverse proxy rule has been configured. This rule will intelligently distribute requests to the appropriate upstream servers based on the configured conditions and weights.