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.com
points to your VMPUBLIC_IP
. - 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
2
to 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/default
- 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