Cloud Native 14 min read

Master APISIX: Deploy a Powerful Cloud‑Native API Gateway with Docker in Minutes

This guide introduces APISIX, a cloud‑native API gateway with visual management and dozens of plugins, walks through its core concepts, shows how to install it via Docker‑Compose, and demonstrates basic and advanced usage such as routing, authentication, rate limiting, and CORS support.

macrozheng
macrozheng
macrozheng
Master APISIX: Deploy a Powerful Cloud‑Native API Gateway with Docker in Minutes
When talking about API gateways, many are familiar with Spring Cloud's Gateway and Zuul, which require configuration changes or custom development. Today we introduce a powerful API gateway, apisix , which comes with visual management and up to thirty plugins.

Overview

APISIX is a cloud‑native microservice API gateway that provides ultimate performance, security, openness, and extensibility. Built on Nginx and etcd, it offers dynamic routing and hot‑loaded plugins, making it especially suitable for microservice environments.

APISIX overview
APISIX overview

Core Concepts

Understanding these core concepts will help you use APISIX effectively.

Upstream: a virtual host that load‑balances requests across multiple target services.

Route: defines rules to match client requests, applies configured plugins, and forwards the request to a specified upstream.

Consumer: identifies the API consumer, often used for authentication.

Service: an abstraction of a group of routes, typically one‑to‑one with an upstream.

Plugin: enhances request handling (e.g., rate limiting, authentication, blacklist) and can be attached to consumers, services, or routes.

Installation

The official Docker‑Compose deployment script allows installation with a single script.

Download the apisix-docker project and use its example directory. Repository: https://github.com/apache/apisix-docker

Upload the example directory to a Linux server.

APISIX directory structure
APISIX directory structure
drwxrwxrwx. 2 root root   25 Jun 19 10:12 apisix_conf   # APISIX config directory
... (other directories omitted for brevity) ...

The docker-compose.yml script launches core services (apisix, apisix‑dashboard, etcd) and two test Nginx services.

version: "3"
services:
  # apisix‑dashboard
  apisix-dashboard:
    image: apache/apisix-dashboard:2.7
    restart: always
    volumes:
      - ./dashboard_conf/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml
    ports:
      - "9000:9000"
    networks:
      - apisix

  # apisix gateway
  apisix:
    image: apache/apisix:2.6-alpine
    restart: always
    volumes:
      - ./apisix_log:/usr/local/apisix/logs
      - ./apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
    depends_on:
      - etcd
    ports:
      - "9080:9080/tcp"
      - "9443:9443/tcp"
    networks:
      - apisix

  # etcd data store
  etcd:
    image: bitnami/etcd:3.4.15
    restart: always
    volumes:
      - ./etcd_data:/bitnami/etcd
    environment:
      ETCD_ENABLE_V2: "true"
      ALLOW_NONE_AUTHENTICATION: "yes"
      ETCD_ADVERTISE_CLIENT_URLS: "http://0.0.0.0:2379"
      ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
    ports:
      - "2379:2379/tcp"
    networks:
      - apisix

  # test Nginx services
  web1:
    image: nginx:1.19.0-alpine
    restart: always
    volumes:
      - ./upstream/web1.conf:/etc/nginx/nginx.conf
    ports:
      - "9081:80/tcp"
    networks:
      - apisix

  web2:
    image: nginx:1.19.0-alpine
    restart: always
    volumes:
      - ./upstream/web2.conf:/etc/nginx/nginx.conf
    ports:
      - "9082:80/tcp"
    networks:
      - apisix

networks:
  apisix:
    driver: bridge

Start all services: docker-compose -p apisix-docker up -d Check status:

docker-compose -p apisix-docker ps
APISIX services status
APISIX services status

Log in to the dashboard (default credentials admin:admin) at http://192.168.5.78:9000/. The UI is clean and the setup is straightforward.

Dashboard screenshot
Dashboard screenshot

Usage

APISIX not only supports basic routing but also offers a rich set of plugins.

Basic Usage

Two test Nginx services ( web1 and web2 ) are already running.

Create an upstream for web1 (virtual host with load‑balancing).

Create upstream for web1
Create upstream for web1

Repeat for web2.

Create upstream for web2
Create upstream for web2

Create a route that points to the web1 upstream.

Create route for web1
Create route for web1

Optionally attach plugins (none selected for this basic demo).

Plugin selection
Plugin selection

Create a similar route for web2.

Create route for web2
Create route for web2

Access the services through APISIX:

http://192.168.5.78:9080/web1/
http://192.168.5.78:9080/web2/
Access web1 via APISIX
Access web1 via APISIX
Access web2 via APISIX
Access web2 via APISIX

Advanced Usage

Enabling plugins unlocks powerful features such as authentication, rate limiting, and CORS.

Authentication

APISIX supports JWT authentication via the jwt-auth plugin.

Create a consumer object.

Create consumer
Create consumer

Enable the jwt-auth plugin on the consumer.

Enable JWT plugin
Enable JWT plugin

Configure the plugin's key and secret.

JWT key and secret
JWT key and secret

Create a route matching /auth/* and attach the jwt-auth plugin.

Route with JWT auth
Route with JWT auth

Obtain a JWT token by calling http://192.168.5.78:9080/apisix/plugin/jwt/sign with the configured key and a custom payload.

Requests without the token receive a 401 response; adding the token in the Authorization header grants access.

Consumer list with JWT
Consumer list with JWT

Rate Limiting

Limit the number of requests per client IP using the limit-count plugin.

Attach limit-count to a route and configure it to limit by remote_addr.

Configure limit-count
Configure limit-count

When the limit is exceeded (e.g., a third request within 30 seconds), APISIX returns a 503 response.

Rate limit triggered
Rate limit triggered

CORS Support

Enable cross‑origin requests by adding the cors plugin.

Attach cors to a route and configure the desired CORS policy.

Enable CORS plugin
Enable CORS plugin

After configuration, the API responses include the appropriate CORS headers.

CORS headers in response
CORS headers in response

Conclusion

Experiencing APISIX shows that a visual‑managed, cloud‑native API gateway can be simple to set up and extremely powerful. If your microservices are cloud‑native, give APISIX a try.

References

The official APISIX documentation is comprehensive and user‑friendly. Going through it will get you up to speed quickly.

Official docs: https://apisix.apache.org/zh/docs/apisix/getting-started

Source code: https://github.com/apache/apisix-docker

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeDockerpluginapi-gatewayAuthenticationCORSrate limitingAPISIX
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.