Set up NGINX + Firewall rules
apt install nginx
vim /etc/nginx/sites-enabled/fastapi_nginx
server {
listen 80;
server_name MYSERVERIP;
location / {
proxy_pass http://127.0.0.1:8003;
}
}
sudo ufw allow 'Nginx HTTP'
sudo ufw enable
sudo service nginx restart
Prep the config database directory
mkdir ~/ovpn-client-configs/
Start the API service
sudo chmod +x ./generate_config
uvicorn bobvpnAPI:app --port 8003
or with pm2: pm2 start "uvicorn bobvpnAPI:app --port 8003" --name bobapi
Generates an OpenVPN config file for a client.
- URL:
/generate_config
- Method:
POST
- Headers:
Content-Type: application/json
Authorization: Bearer {api-key}
- Parameters:
client_name
(string): The name of the client for whom to generate the config file.
- Response:
- 200 OK:
- Content-Type: application/octet-stream
- Body: The generated OpenVPN config file.
- 401 Unauthorized:
- Body: Invalid or missing API Key.
- 200 OK:
POST /generate_config HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Authorization: Bearer BOBVPNISTHEBEST
{
"client_name": "john_doe"
}
Response:
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="john_doe.ovpn"
<contents of the generated OpenVPN config file>
or
HTTP/1.1 401 Unauthorized
Content-Type: application/json
{
"detail": "Invalid or missing API Key"
}