Installing APISIX
- Open a terminal on your VM.
- Make a folder for APISIX:
sudo mkdir -p /opt/apisix - Create the file
/opt/apisix/apisix.yaml:sudo nano /opt/apisix/apisix.yaml - Copy and paste exactly this content into
apisix.yaml. ReplaceYOUR_BASE64_DEMO_TOKENandYOUR_BASE64_LIVE_TOKENwith your real Base64(API_KEY:SECRET_KEY) strings:apisix: node_listen: 9080 # APISIX will listen on port 9080 for HTTP consumers: - username: finmars # a name for this client plugins: basic-auth: username: foo # user name you want to use for APISIX basic auth password: bar # password you want to use for APISIX basic auth upstreams: - id: 1 nodes: api-demo.exante.eu:443: 1 scheme: https pass_host: node type: roundrobin - id: 2 nodes: api-live.exante.eu:443: 1 scheme: https pass_host: node type: roundrobin plugin_configs: - id: 1 plugins: basic-auth: {} proxy-rewrite: headers: set: # Replace this with your Base64(API_KEY:SECRET_KEY) for the demo environment Authorization: "Basic %TOKEN%" regex_uri: - "^/demo/(.*)" - "/$1" - id: 2 plugins: basic-auth: {} proxy-rewrite: headers: set: # Replace this with your Base64(API_KEY:SECRET_KEY) for the live environment Authorization: "Basic %TOKEN%" regex_uri: - "^/live/(.*)" - "/$1" routes: - uris: - /demo/md/*/accounts - /demo/md/*/symbols/* - /demo/md/*/summary/* - /demo/md/*/ohlc/* - /demo/md/*/transactions - /demo/md/*/crossrates/* - /demo/trade/*/orders/* upstream_id: 1 plugin_config_id: 1 - uris: - /live/md/*/accounts - /live/md/*/symbols/* - /live/md/*/summary/* - /live/md/*/ohlc/* - /live/md/*/transactions - /live/md/*/crossrates/* - /live/trade/*/orders/* upstream_id: 2 plugin_config_id: 2 deployment: role: data_plane role_data_plane: config_provider: yaml #END - Save and close the file:
- Press
Ctrl+O, thenEnterto save. - Press
Ctrl+Xto exit Nano.
- Press
2. Create a restart script for APISIX
- In the terminal, make a new script:
nano /opt/apisix/restart_apisix.sh - Copy and paste this into
restart_apisix.sh:#!/bin/bash # If a container named "apache-apisix" exists, stop and remove it if docker ps -a --format '{{.Names}}' | grep -Eq "^apache-apisix\$"; then echo "Stopping and removing existing apache-apisix container..." docker stop apache-apisix docker rm apache-apisix fi echo "Starting a new APISIX container..." docker run -d \ --name apache-apisix \ -p 9080:9080 \ -e APISIX_STAND_ALONE=true \ -v /opt/apisix/apisix.yaml:/usr/local/apisix/conf/config.yaml \ -v /opt/apisix/apisix.yaml:/usr/local/apisix/conf/apisix.yaml \ apache/apisix echo "APISIX container is now running." - Save and close:
- Press
Ctrl+O, thenEnter. - Press
Ctrl+X.
- Press
- Make the script executable:
chmod +x /opt/apisix/restart_apisix.sh
3. Run APISIX for the first time
- In the terminal, run:
./restart_apisix.sh - Wait a few seconds. APISIX will start in Docker, listening on port 9080, reading your
/opt/apisix/apisix.yamlas bothconfig.yamlandapisix.yaml. - Check that it is running:
sudo docker ps
You should see a line forapache/apisixwith0.0.0.0:9080->9080/tcp. - Look at the logs to ensure no errors:
sudo docker logs apache-apisix
You should see messages like “config file … reloaded” and no errors.
4. Test APISIX locally with curl (no Nginx yet)
- In the terminal, run:
curl -u foo:bar http://127.0.0.1:9080/demo/md/3.0/accounts-u foo:barsends your Basic Auth.- The path
/demo/md/3.0/accountsmatches your route pattern/demo/md/*/accounts.
- If everything is correct, you will see JSON returned from Exante.
If you see{"error_msg":"404 Route Not Found"}, double-check that the path matches exactly and that your tokens are correct.