
Deploy Golang API to VPS with Nginx and HTTPS (Step-by-Step Production Guide)
๐ Deploy Golang API to VPS with Nginx & HTTPS This guide documents the complete production deployment process of a Golang API to a VPS. Prerequisites: A VPS with Ubuntu 22.04 (You can get one from SumoPod) A domain name (You can get one from Namecheap | Cloudflare | etc) A Golang API We will: Install required packages Configure firewall (UFW) Clone project Configure environment variables Build and run binary Setup systemd service Configure Nginx reverse proxy Point custom domain Enable HTTPS (SSL) Verify auto renewal ๐ Final Architecture Internet โ HTTPS (443) โ Nginx Reverse Proxy โ http://localhost:6969 โ Go Binary (/opt/<appname>/<appname>) โ systemd Service Phase 1 โ Install Requirements # Connect to your vps ssh root@YOUR_VPS_IP # Update package list sudo apt update && sudo apt upgrade -y # Install Nginx, Git, Certbot, and Build Tools sudo apt install -y git uvw curl nginx build-essential Description: - git: version control system - uvw: (Uncomplicated Firewall) tool for managing firewall rules - curl: tool for transferring data with URLs - nginx: web server and reverse proxy - build-essential: collection of packages required for building software from source code Phase 2 - Create propper user # Create a new user sudo adduser vicktor # Add the user to the sudo group sudo usermod -aG sudo vicktor # Switch to the new user su - vicktor Phase 3 โ Configure Firewall (UFW) # Allow SSH, Nginx Full sudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' Enable UFW sudo ufw enable Check status sudo ufw status Output: ...