π Automated SSL Setup Tool for Nginx with mkcert
A production-ready Rust CLI tool that automates SSL certificate generation and Nginx configuration for local development using mkcert.
- β Automatic mkcert installation - Detects and installs mkcert if not present
- π SSL certificate generation - Creates trusted local SSL certificates
- βοΈ Nginx auto-configuration - Generates and deploys production-ready Nginx configs
- π Service management - Optionally manage systemd services
- π Configuration tracking - Keeps track of all managed domains
- π¨ Beautiful CLI - Colored output with progress indicators
- π‘οΈ SOLID principles - Clean, maintainable, and extensible architecture
- π Status monitoring - Check health of all configured domains
- ποΈ Easy cleanup - Remove domains and certificates with one command
Built with SOLID principles for maximum maintainability:
- Single Responsibility: Each module handles one specific concern
- Open/Closed: Easy to extend with new certificate providers or web servers
- Liskov Substitution: Trait-based design allows swapping implementations
- Interface Segregation: Small, focused interfaces
- Dependency Inversion: Depends on abstractions, not concrete implementations
localstacker/
βββ src/
β βββ main.rs # CLI entry point
β βββ error.rs # Custom error types
β βββ config.rs # Configuration management
β βββ utils.rs # Utility functions
β βββ core/
β β βββ mod.rs # Core traits
β β βββ mkcert.rs # Certificate provider impl
β β βββ nginx.rs # Web server config impl
β β βββ systemd.rs # System service impl
β β βββ file_ops.rs # File operations impl
β βββ commands/
β βββ mod.rs
β βββ setup.rs # Setup command
β βββ list.rs # List domains
β βββ remove.rs # Remove domain
β βββ status.rs # Check status
β βββ install_mkcert.rs # Install mkcert
βββ Cargo.toml
- Nginx installed and running
- Root/sudo access
- Rust 1.70+ (will be auto-installed if missing)
git clone https://github.com/ekosuprianto96/localstacker.git
cd localstacker
# Run install script (builds and installs automatically)
chmod +x install.sh
./install.shThe script will:
- β Check/install Rust if needed
- β Build optimized release binary
- β
Install to
/usr/local/bin/(if running as root)
git clone https://github.com/ekosuprianto96/localstacker.git
cd localstacker
# Build and install (requires sudo)
make installgit clone https://github.com/ekosuprianto96/localstacker.git
cd localstacker
# Build release binary
cargo build --release
# Install system-wide
sudo cp target/release/localstacker /usr/local/bin/
# Or install for current user only
mkdir -p ~/.local/bin
cp target/release/localstacker ~/.local/bin/
# Add ~/.local/bin to PATH in your shell configlocalstacker --version
localstacker --helpsudo localstacker setup \
--domain myapp.local \
--port 3000With systemd service integration:
sudo localstacker setup \
--domain myapp.local \
--port 3000 \
--service myapp.serviceSkip confirmation prompts:
sudo localstacker setup \
--domain myapp.local \
--port 3000 \
--yesRe-run setup to regenerate certificates or update configuration (auto-updates existing domain):
sudo localstacker setup \
--domain myapp.local \
--port 4000 \
--yesUse custom Nginx template:
sudo localstacker setup \
--domain myapp.local \
--port 3000 \
--template ./custom-nginx.confsudo localstacker listShow detailed information:
sudo localstacker list --detailedCheck all domains:
sudo localstacker statusCheck specific domain:
sudo localstacker status myapp.localsudo localstacker remove myapp.localAlso remove SSL certificates:
sudo localstacker remove myapp.local --remove-certsSkip confirmation:
sudo localstacker remove myapp.local --yessudo localstacker install-mkcertForce reinstall:
sudo localstacker install-mkcert --force--verboseor-v: Enable verbose output--dry-runor-n: Show what would be done without executing
Example:
sudo localstacker setup --domain test.local --port 8080 --verbose --dry-runWhen you run setup, the tool:
- β Checks if mkcert is installed (installs if missing)
- π Installs local CA (if not already installed)
- π Generates SSL certificate for the domain
- π Copies certificates to
/etc/nginx/ssl/ - βοΈ Generates Nginx configuration with:
- HTTP to HTTPS redirect
- SSL/TLS settings
- Security headers
- WebSocket support
- Proxy configuration
- π Enables the site (creates symlink)
- βοΈ Tests Nginx configuration
- π Reloads Nginx
- π― Optionally restarts specified systemd service
- πΎ Saves configuration for future management
The tool generates a production-ready Nginx config with:
- HTTPS redirect from HTTP
- TLS 1.2 and 1.3 support
- Security headers (HSTS, X-Frame-Options, etc.)
- Proxy headers for backend compatibility
- WebSocket support
- Optimized timeouts and buffering
- Access and error logging
- Local development with HTTPS
- Microservices development environment
- Testing production-like SSL setup
- DevOps automation for team environments
- CI/CD local testing
- Uses mkcert for locally-trusted certificates
- Certificates are only trusted on the local machine
- Not suitable for production - use Let's Encrypt or similar for production
- Requires root access for Nginx configuration
Thanks to SOLID design, you can easily:
// Implement the CertificateProvider trait
pub struct LetsEncryptProvider;
impl CertificateProvider for LetsEncryptProvider {
// ... implement methods
}// Implement the WebServerConfig trait
pub struct ApacheConfig;
impl WebServerConfig for ApacheConfig {
// ... implement methods
}- Create a new file in
src/commands/ - Add command to
main.rsenum - Implement the command logic
Make sure you're running with sudo:
sudo localstacker setup --domain test.local --port 3000Check Nginx configuration manually:
sudo nginx -tMake sure another service isn't already using the port:
sudo ss -tlnp | grep :3000Reinstall mkcert CA:
sudo localstacker install-mkcert --forceMIT License - feel free to use in your projects!
Contributions are welcome! The codebase follows SOLID principles to make it easy to:
- Add new features
- Fix bugs
- Improve documentation
- Add tests
Built with:
- clap - CLI argument parsing
- mkcert - Local certificate generation
- Nginx - Web server / reverse proxy
Made with β€οΈ for developers who want HTTPS in local development