Skip to content

Latest commit

 

History

History
141 lines (95 loc) · 2.91 KB

File metadata and controls

141 lines (95 loc) · 2.91 KB

nginx-modsite (Enhanced)

A robust, interactive CLI tool to manage Nginx virtual hosts using the standard:

  • /etc/nginx/sites-available
  • /etc/nginx/sites-enabled

This script provides a safe and ergonomic interface for enabling, disabling, editing, listing, and reloading Nginx sites with built-in validation and error handling.


Features

  • Enable / disable sites using symlinks (best practice)
  • Interactive site selection (no need to remember names)
  • Automatic Nginx configuration validation (nginx -t)
  • Optional automatic reload after changes
  • Safe input validation (prevents invalid site names)
  • Root privilege enforcement
  • Colored CLI output for better UX
  • Supports both:
    • systemctl
    • legacy service

Requirements

  • Linux system with Nginx installed
  • Bash (>= 4.x recommended)
  • Root privileges (sudo)

Installation

sudo cp nginx-modsite /usr/local/sbin/nginx-modsite
sudo chmod +x /usr/local/sbin/nginx-modsite

Verify installation:

nginx-modsite --help

Usage

nginx-modsite [OPTION] [SITE]

Options

Option Description
-e, --enable [SITE] Enable a site (create symlink)
-d, --disable [SITE] Disable a site (remove symlink)
-x, --edit [SITE] Edit site configuration
-l, --list List all sites with status
-r, --reload Test and reload Nginx
-y, --yes Auto-reload without prompt
-h, --help Show help

Examples

Enable a site

sudo nginx-modsite --enable mysite.conf

Or interactively:

sudo nginx-modsite --enable

Disable a site

sudo nginx-modsite --disable mysite.conf

Edit a site

sudo nginx-modsite --edit mysite.conf

List sites

sudo nginx-modsite --list

Reload Nginx manually

sudo nginx-modsite --reload

Enable with auto-reload

sudo nginx-modsite --enable mysite.conf --yes

Disclaimer

This script is provided "as is", without warranty of any kind, express or implied.
Use it at your own risk.

While nginx-modsite includes safeguards such as configuration validation (nginx -t) and input sanitization, it directly modifies your system’s Nginx configuration by creating and removing symbolic links in critical directories.

The author(s) are not responsible for:

  • Misconfiguration of Nginx
  • Service downtime or interruption
  • Data loss or system instability
  • Security issues resulting from improper use

Before using this script in production, you should:

  • Understand how Nginx site management works (sites-available / sites-enabled)
  • Test configurations in a staging environment
  • Maintain backups of your Nginx configuration files
  • Review changes before reloading the service

By using this tool, you acknowledge that you are fully responsible for any impact it may have on your system.

License

MIT License