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.
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.
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-dockerproject and use its
exampledirectory. Repository: https://github.com/apache/apisix-docker
Upload the
exampledirectory to a Linux server.
<code>drwxrwxrwx. 2 root root 25 Jun 19 10:12 apisix_conf # APISIX config directory
... (other directories omitted for brevity) ...
</code>The
docker-compose.ymlscript launches core services (apisix, apisix‑dashboard, etcd) and two test Nginx services.
<code>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
</code>Start all services:
docker-compose -p apisix-docker up -dCheck status:
docker-compose -p apisix-docker psLog in to the dashboard (default credentials
admin:admin) at
http://192.168.5.78:9000/. The UI is clean and the setup is straightforward.
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).
Repeat for
web2.
Create a route that points to the
web1upstream.
Optionally attach plugins (none selected for this basic demo).
Create a similar route for
web2.
Access the services through APISIX:
http://192.168.5.78:9080/web1/ http://192.168.5.78:9080/web2/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.
Enable the
jwt-authplugin on the consumer.
Configure the plugin's
keyand
secret.
Create a route matching
/auth/*and attach the
jwt-authplugin.
Obtain a JWT token by calling
http://192.168.5.78:9080/apisix/plugin/jwt/signwith the configured
keyand a custom
payload.
Requests without the token receive a 401 response; adding the token in the
Authorizationheader grants access.
Rate Limiting
Limit the number of requests per client IP using the limit-count plugin.
Attach
limit-countto a route and configure it to limit by
remote_addr.
When the limit is exceeded (e.g., a third request within 30 seconds), APISIX returns a 503 response.
CORS Support
Enable cross‑origin requests by adding the cors plugin.
Attach
corsto a route and configure the desired CORS policy.
After configuration, the API responses include the appropriate CORS headers.
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
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.