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.
- 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
- Linux system with Nginx installed
- Bash (>= 4.x recommended)
- Root privileges (
sudo)
sudo cp nginx-modsite /usr/local/sbin/nginx-modsite
sudo chmod +x /usr/local/sbin/nginx-modsiteVerify installation:
nginx-modsite --helpnginx-modsite [OPTION] [SITE]| 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 |
sudo nginx-modsite --enable mysite.confOr interactively:
sudo nginx-modsite --enablesudo nginx-modsite --disable mysite.confsudo nginx-modsite --edit mysite.confsudo nginx-modsite --listsudo nginx-modsite --reloadsudo nginx-modsite --enable mysite.conf --yesThis 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.
MIT License