Reverse Proxy

This page is based on the following example:

https://github.com/aileron-gateway/aileron-gateway/tree/main/examples/reverse-proxy/

Reverse Proxy

Overview

This example runs a reverse-proxy server. A revere-proxy server, which is the very basic feature in API Gateways, proxy requests from client to upstream services.

block-beta
  columns 6
  Downstream:1
  space:1
  block:aileron:2
    HTTPServer["πŸŸͺ</br>HTTP</br>Server"]
    ReverseProxyHandler["πŸŸ₯</br>ReverseProxy</br>Handler"]
  end
  space:1
  Upstream:1

Downstream --> HTTPServer
HTTPServer --> Downstream
Upstream --> ReverseProxyHandler
ReverseProxyHandler --> Upstream

style Downstream stroke:#888
style Upstream stroke:#888
style ReverseProxyHandler stroke:#ff6961,stroke-width:2px

Legend:

  • πŸŸ₯ #ff6961 Handler resources.
  • 🟩 #77dd77 Middleware resources (Server-side middleware).
  • 🟦 #89CFF0 Tripperware resources (Client-side middleware).
  • πŸŸͺ #9370DB Other resources.

In this example, following directory structure and files are supposed. If you need a pre-built binary, download from GitHub Releases.

reverse-proxy/     ----- Working directory.
β”œβ”€β”€ aileron        ----- AILERON Gateway binary (aileron.exe on windows).
└── config.yaml    ----- AILERON Gateway config file.

Config

Configuration yaml to run a reverse-proxy server would becomes as follows.

# config.yaml

apiVersion: core/v1
kind: Entrypoint
spec:
  runners:
    - apiVersion: core/v1
      kind: HTTPServer

---
apiVersion: core/v1
kind: HTTPServer
spec:
  addr: ":8080"
  virtualHosts:
    - handlers:
        - handler:
            apiVersion: core/v1
            kind: ReverseProxyHandler

---
apiVersion: core/v1
kind: ReverseProxyHandler
spec:
  loadBalancers:
    - pathMatcher:
        match: "/"
        matchType: Prefix
      upstreams:
        - url: http://httpbin.org

The config tells:

  • Start a HTTPServer with port 8080.
  • ReverseProxy is applied for the path having prefix /.
  • Upstream service is http://httpbin.org.

This graph shows the resource dependencies of the configuration.

graph TD
  Entrypoint["πŸŸͺ **Entrypoint**</br>default/default"]
  HTTPServer["πŸŸͺ **HTTPServer**</br>default/default"]
  ReverseProxyHandler["πŸŸ₯ **ReverseProxyHandler**</br>default/default"]

Entrypoint --"Runner"--> HTTPServer
HTTPServer --"HTTP Handler"--> ReverseProxyHandler
ReverseProxyHandler

style ReverseProxyHandler stroke:#ff6961,stroke-width:2px

Run

Run the AILERON Gateway with:

./aileron -f ./config.yaml

Check

After running a reverse-proxy server, send HTTP requests to it.

A json response will be returned when the reverse-proxy server is correctly running.

$ curl http://localhost:8080/get
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.68.0",
    "X-Amzn-Trace-Id": "Root=1-68146a36-66235c683c6d7ae90b60c969",
    "X-Forwarded-Host": "localhost:8080"
  },
  "origin": "127.0.0.1, 106.73.5.65",
  "url": "http://localhost:8080/get"
}

Additional resources

Here’s the some nice apis that can be used for testing.

Available with NO configuration.

Available after configuration.

Local mock server.


Last modified June 2, 2025: update docs (df954a4)