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_TOKEN
andYOUR_BASE64_LIVE_TOKEN
with your real Base64(API_KEY:SECRET_KEY) strings:role: data_plane apisix: node_listen: 9080 # APISIX listens on port 9080 for HTTP consumers: - username: finmars plugins: basic-auth: username: foo # Basic auth user for APISIX password: bar # Basic auth password for APISIX 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 with your Base64(API_KEY:SECRET_KEY) for demo Authorization: "Basic YOUR_BASE64_DEMO_TOKEN" regex_uri: - "^/demo/(.*)" - "/$1" - id: 2 plugins: basic-auth: {} proxy-rewrite: headers: set: # Replace with your Base64(API_KEY:SECRET_KEY) for live Authorization: "Basic YOUR_BASE64_LIVE_TOKEN" regex_uri: - "^/live/(.*)" - "/$1" routes: - priority: 0 status: 1 uris: - /demo/md/*/accounts - /demo/md/*/symbols/* - /demo/md/*/summary/* - /demo/md/*/ohlc/* - /demo/md/*/transactions - /demo/trade/*/orders/* upstream_id: 1 plugin_config_id: 1 - priority: 0 status: 1 uris: - /live/md/*/accounts - /live/md/*/symbols/* - /live/md/*/summary/* - /live/md/*/ohlc/* - /live/md/*/transactions - /live/trade/*/orders/* upstream_id: 2 plugin_config_id: 2 #END
- Save and close the file:
- Press
Ctrl+O
, thenEnter
to save. - Press
Ctrl+X
to 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.yaml
as bothconfig.yaml
andapisix.yaml
. - Check that it is running:
sudo docker ps
You should see a line forapache/apisix
with0.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:bar
sends your Basic Auth.- The path
/demo/md/3.0/accounts
matches 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.
5. Install and configure Nginx and Let’s Encrypt
5.1. Install Nginx
Update package lists:sudo apt updateInstall Nginx:sudo apt install nginx -yStart and enable Nginx:sudo systemctl start nginx sudo systemctl enable nginx
5.2. Install Certbot for Let’s Encrypt
Add repositories and update:sudo apt install software-properties-common -y sudo add-apt-repository universe sudo add-apt-repository ppa:certbot/certbot -y sudo apt updateInstall Certbot with Nginx plugin:sudo apt install certbot python3-certbot-nginx -y
5.3. Obtain a certificate for your domain
Make sure your DNS A record forabeta-proxy.finmars.compoints to16.170.231.65.Run:sudo certbot --nginx -d abeta-proxy.finmars.comFollow the prompts:Enter your email, then pressEnter.Agree to terms by typingA, thenEnter.Choose option2to redirect HTTP to HTTPS, thenEnter.
Certbot will create an Nginx site file and install the certificate under /etc/letsencrypt/live/abeta-proxy.finmars.com/.
6. Configure Nginx to proxy to APISIX
Open the site file Certbot created:sudo nano /etc/nginx/sites-available/abeta-proxy.finmars.com.confInside theserver { ... }block for port 443, find these lines:listen 443 ssl; server_name abeta-proxy.finmars.com; ssl_certificate /etc/letsencrypt/live/abeta-proxy.finmars.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/abeta-proxy.finmars.com/privkey.pem;Right below them, add:location / { proxy_pass http://127.0.0.1:9080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }After editing, thatserver { }block looks like:server { listen 443 ssl; server_name abeta-proxy.finmars.com; ssl_certificate /etc/letsencrypt/live/abeta-proxy.finmars.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/abeta-proxy.finmars.com/privkey.pem; location / { proxy_pass http://127.0.0.1:9080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }Make sure there is also a block that redirects HTTP to HTTPS. It looks like:server { listen 80; server_name abeta-proxy.finmars.com; return 301 https://$host$request_uri; }Save and close:PressCtrl+O, thenEnter.PressCtrl+X.
Test Nginx configuration:sudo nginx -tYou should see “syntax is ok” and “test is successful”.Reload Nginx so it uses the new config:sudo systemctl reload nginx
7. Open firewall ports (if you use UFW)
Allow HTTP (port 80) and HTTPS (port 443), and APISIX port (9080) in UFW:sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw allow 9080/tcpCheck UFW status:sudo ufw status
8. Final tests
Test HTTPS through Nginx:In a browser or terminal, go to:https://abeta-proxy.finmars.com/demo/md/3.0/accountsEnter Basic Auth userfooand passwordbar.If your Base64 tokens are correct, you see JSON from Exante.
Test other routes:https://abeta-proxy.finmars.com/live/md/3.0/accountsUse the same Basic Auth.Should return JSON if live token is correct.
Test local APISIX again (no Nginx):curl -u foo:bar http://127.0.0.1:9080/demo/md/3.0/accountsThis hits APISIX directly, without Nginx.Should return JSON if config is correct.
9. Automatic certificate renewal
Certbot already set up automatic renewal.To test renewal, run:sudo certbot renew --dry-runIf it says “Congratulations, all renewals succeeded,” your auto-renew is working.
10. How to update your APISIX config later
Edit/opt/apisix/apisix.yamlany time:sudo nano /opt/apisix/apisix.yamlSave changes and exit.Run the restart script:./restart_apisix.shCheck logs:sudo docker logs apache-apisixTest again withcurlor in a browser.
Complete Recap
Create folder/opt/apisix.Create and fill/opt/apisix/apisix.yaml(withrole: data_plane, consumers, upstreams, plugin_configs, routes, and#END).Makerestart_apisix.shscript that stops any old container and starts a new one, mounting/opt/apisix/apisix.yamlas bothconfig.yamlandapisix.yaml.Run./restart_apisix.shto start APISIX.TestAPISIX locally:curl -u foo:bar http://127.0.0.1:9080/demo/md/3.0/accounts.Install Nginx(sudo apt install nginx).Install Certbot(sudo apt install certbot python3-certbot-nginx).Get SSL:sudo certbot --nginx -d abeta-proxy.finmars.com.Edit Nginx siteat/etc/nginx/sites-available/abeta-proxy.finmars.com.confto add:location / { proxy_pass http://127.0.0.1:9080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }Reload Nginx(sudo nginx -tthensudo systemctl reload nginx).Open firewallports 80, 443, 9080 (sudo ufw allow ...).Testhttps://abeta-proxy.finmars.com/demo/md/3.0/accountsin a browser.Auto-renewis handled by Certbot.To update, edit/opt/apisix/apisix.yamland run./restart_apisix.sh.
That is the full, clear set of instructions. Now your APISIX runs behind Nginx with a Let’s Encrypt SSL certificate, and you can update the config anytime by editing the file and restarting with the script.