Skip to content

Connect your own backend

TutorialLearn by doing, one step after another.

The quick start routed to the built-in demo backend. This page connects a real service and covers what usually comes up on the first day: paths, hosts, TLS, health and timeouts.

1. Declare the upstream

Develop → Upstreams → New upstream. Fill in the form, or switch to Code (YAML) and paste a definition:

apiVersion: apinx/v1
kind: Upstream
name: orders-service
targets:
  - url: http://10.0.0.5:8080
  - url: http://10.0.0.6:8080
balancer: round_robin
health:
  passive:
    enabled: true           # eject a target after 5 failed requests, for 30 s
timeouts:
  connect: 5s
  response_header: 30s
  total: 60s

In a full gateway file the same object is an entry of upstreams:, without apiVersion and kind.

A target URL may carry a base path (http://host:8080/api); it is prepended to every forwarded path. Several targets are balanced round robin by default; weighted, least_connections and consistent_hash (by header, cookie or client IP) are available. A gRPC service is a target written grpc://host:port (HTTP/2 without TLS) or grpcs://host: gRPC services.

2. Expose it as an API

apiVersion: apinx/v1
kind: API
name: orders
base_path: /orders
upstream: orders-service
strip_prefix: true              # /orders/items → /items at the backend
operations:
  - name: all
    path: /{rest...}

strip_prefix removes exactly the API's base path. To keep the prefix, set it to false. To rewrite further, use transform with path.add_prefix, strip_prefix or replace.

3. The Host header

By default the backend receives the target's host in Host, which is what most services and cloud load balancers expect. If your backend routes by the caller's host name, set pass_host_header: true on the upstream.

4. HTTPS backends

upstreams:
  - name: partner
    targets:
      - url: https://api.partner.example
    tls:
      server_name: api.partner.example   # SNI, when it differs from the URL host
      ca_file: /etc/apinx/partner-ca.pem
      client_cert_file: /etc/apinx/client.crt   # mutual TLS to the backend
      client_key_file: /etc/apinx/client.key

A private certificate authority can also be given as PEM text in tls.ca instead of a file path, which is the only form Apinx Cloud accepts: a hosted gateway reads no files, so a deploy naming ca_file, client_cert_file or client_key_file is refused (APX-SAAS-0070), and so is one that turns verification off (APX-SAAS-0071). On premises insecure_skip_verify exists for test environments and is refused by nothing but your judgement.

    tls:
      ca: |
        -----BEGIN CERTIFICATE-----
        MIIB...
        -----END CERTIFICATE-----

5. Serve HTTPS to callers

listeners:
  - name: https
    address: ":8443"
    protocol: https
    tls:
      certificates:
        - cert_file: /etc/apinx/api.crt
          key_file: /etc/apinx/api.key
      min_version: "1.2"

Several certificates are selected by SNI. HTTP/2 is negotiated through ALPN; on plain HTTP listeners h2c: true enables cleartext HTTP/2. Client certificates can be requested or required (client_auth, client_ca_file).

6. Check it

  • Overview shows the upstream's health from the proxy's point of view.
  • curl -i localhost:8080/orders/items should answer from your backend with the prefix stripped.
  • Analyze → Traffic shows the backend call, its duration and every attempt.
  • If callers get 503 APX-UP-0001, no target is healthy: check the target URL and the backend's own health.

Next: Resilient upstreams for retries, breakers and active checks.