Skip to content

Repository files navigation

Localsatcker CLI

πŸš€ 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.

✨ Features

  • βœ… 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

πŸ—οΈ Architecture

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

Project Structure

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

πŸ“¦ Installation

Prerequisites

  • Nginx installed and running
  • Root/sudo access
  • Rust 1.70+ (will be auto-installed if missing)

Option 1: Quick Install (Recommended)

git clone https://github.com/ekosuprianto96/localstacker.git
cd localstacker

# Run install script (builds and installs automatically)
chmod +x install.sh
./install.sh

The script will:

  • βœ… Check/install Rust if needed
  • βœ… Build optimized release binary
  • βœ… Install to /usr/local/bin/ (if running as root)

Option 2: Using Makefile

git clone https://github.com/ekosuprianto96/localstacker.git
cd localstacker

# Build and install (requires sudo)
make install

Option 3: Manual Build

git 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 config

Verify Installation

localstacker --version
localstacker --help

πŸš€ Usage

Setup SSL for a domain

sudo localstacker setup \
  --domain myapp.local \
  --port 3000

With systemd service integration:

sudo localstacker setup \
  --domain myapp.local \
  --port 3000 \
  --service myapp.service

Skip confirmation prompts:

sudo localstacker setup \
  --domain myapp.local \
  --port 3000 \
  --yes

Re-run setup to regenerate certificates or update configuration (auto-updates existing domain):

sudo localstacker setup \
  --domain myapp.local \
  --port 4000 \
  --yes

Use custom Nginx template:

sudo localstacker setup \
  --domain myapp.local \
  --port 3000 \
  --template ./custom-nginx.conf

List all configured domains

sudo localstacker list

Show detailed information:

sudo localstacker list --detailed

Check domain status

Check all domains:

sudo localstacker status

Check specific domain:

sudo localstacker status myapp.local

Remove a domain

sudo localstacker remove myapp.local

Also remove SSL certificates:

sudo localstacker remove myapp.local --remove-certs

Skip confirmation:

sudo localstacker remove myapp.local --yes

Install mkcert

sudo localstacker install-mkcert

Force reinstall:

sudo localstacker install-mkcert --force

Global Options

  • --verbose or -v: Enable verbose output
  • --dry-run or -n: Show what would be done without executing

Example:

sudo localstacker setup --domain test.local --port 8080 --verbose --dry-run

πŸ”§ What it does

When you run setup, the tool:

  1. βœ… Checks if mkcert is installed (installs if missing)
  2. πŸ” Installs local CA (if not already installed)
  3. πŸ“œ Generates SSL certificate for the domain
  4. πŸ“ Copies certificates to /etc/nginx/ssl/
  5. βš™οΈ Generates Nginx configuration with:
    • HTTP to HTTPS redirect
    • SSL/TLS settings
    • Security headers
    • WebSocket support
    • Proxy configuration
  6. πŸ”— Enables the site (creates symlink)
  7. βœ”οΈ Tests Nginx configuration
  8. πŸ”„ Reloads Nginx
  9. 🎯 Optionally restarts specified systemd service
  10. πŸ’Ύ Saves configuration for future management

πŸ“ Generated Nginx Configuration

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

🎯 Use Cases

  • Local development with HTTPS
  • Microservices development environment
  • Testing production-like SSL setup
  • DevOps automation for team environments
  • CI/CD local testing

πŸ” Security Notes

  • 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

πŸ› οΈ Extending the Tool

Thanks to SOLID design, you can easily:

Add a new certificate provider

// Implement the CertificateProvider trait
pub struct LetsEncryptProvider;

impl CertificateProvider for LetsEncryptProvider {
    // ... implement methods
}

Add a new web server

// Implement the WebServerConfig trait
pub struct ApacheConfig;

impl WebServerConfig for ApacheConfig {
    // ... implement methods
}

Add a new command

  1. Create a new file in src/commands/
  2. Add command to main.rs enum
  3. Implement the command logic

πŸ› Troubleshooting

Permission denied

Make sure you're running with sudo:

sudo localstacker setup --domain test.local --port 3000

Nginx test failed

Check Nginx configuration manually:

sudo nginx -t

Port already in use

Make sure another service isn't already using the port:

sudo ss -tlnp | grep :3000

Certificate not trusted

Reinstall mkcert CA:

sudo localstacker install-mkcert --force

πŸ“„ License

MIT License - feel free to use in your projects!

🀝 Contributing

Contributions are welcome! The codebase follows SOLID principles to make it easy to:

  • Add new features
  • Fix bugs
  • Improve documentation
  • Add tests

πŸ™ Credits

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

About

A production-ready Rust CLI tool that automates SSL certificate generation and Nginx configuration for local development using mkcert.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages