You can configure APISIX using its Admin API. The following examples demonstrate how to create services with round-robin upstreams, map routes to those services based on hostnames, and configure SSL certificates for subdomains.
Note: All requests require the X-API-KEY header. In this example, the key is edd1c9f034335f136f87ad84b625c8f1.
# Create service 1 with web1 upstream
curl http://127.0.0.1:9180/apisix/admin/services/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{
"upstream": {
"type": "roundrobin",
"nodes": {
"web1:80": 1
}
}
}'
# Create route 12 for host web1.lvh.me linked to service 1
curl http://127.0.0.1:9180/apisix/admin/routes/12 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{
"uri": "/*",
"host": "web1.lvh.me",
"service_id": "1"
}'
# Configure SSL for lvh.me
curl http://127.0.0.1:9180/apisix/admin/ssl/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d "{\n \"cert\": \"$( cat './mkcert/lvh.me+1.pem')\",\n \"key\": \"$( cat './mkcert/lvh.me+1-key.pem')\",\n \"sni\": \"lvh.me\"\n}"