Install Nginx Proxy
5. Install and configure Nginx and Let’s Encrypt
5.1. Install Nginx
- Update package lists:
sudo apt update - Install Nginx:
sudo apt install nginx -y - Start 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 update - Install 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 for
abeta-proxy.finmars.compoints to16.170.231.65. - Run:
sudo certbot --nginx -d abeta-proxy.finmars.com - Follow the prompts:
- Enter your email, then press
Enter. - Agree to terms by typing
A, thenEnter. - Choose option
2to redirect HTTP to HTTPS, thenEnter.
- Enter your email, then press
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.conf - Inside the
server { ... }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:
- Press
Ctrl+O, thenEnter. - Press
Ctrl+X.
- Press
- Test Nginx configuration:
sudo nginx -t
You 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/tcp - Check 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/accounts- Enter Basic Auth user
fooand passwordbar. - If your Base64 tokens are correct, you see JSON from Exante.
- Enter Basic Auth user
- Test other routes:
https://abeta-proxy.finmars.com/live/md/3.0/accounts- Use 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/accounts- This 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-run - If 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.yaml - Save changes and exit.
- Run the restart script:
./restart_apisix.sh - Check logs:
sudo docker logs apache-apisix - Test again with
curlor 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). - Make
restart_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. - Test APISIX 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 site at
/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 firewall ports 80, 443, 9080 (
sudo ufw allow ...). - Test
https://abeta-proxy.finmars.com/demo/md/3.0/accountsin a browser. - Auto-renew is 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.