NX - Nginx Site Manager#
A lightweight, colorized Bash utility to manage Nginx virtual hosts using the sites-available / sites-enabled pattern.
It replaces the need for manual ln -s and rm commands with a simple, human-readable interface.
Features#
- Container Support: Works in containerized contexts via environment variable configuration.
- Tree-view Listing: Automatically groups subdomains under their parent domains using ASCII logic.
$ sudo nx list SITE STATUS ---------------------------------------- ---------- default Disabled ● example.com Enabled └── ● knot.example.com Enabled └── ● pds.example.com Enabled └── statusphere.example.com Disabled ● example.net Enabled └── ● staging.example.net Enabled └── wiki.example.net Disabled └── ws.example.net Disabled - Status Indicators: Color-coded feedback for "Enabled" (Green) and "Disabled" sites.
- Smart Suffixes: Automatically handles .conf extensions so you don't have to type them.
- Integrated Testing: Prompts to run
nginx -tand reload the service after every edit or toggle. - Config Preview: Uses batcat (with syntax highlighting) if installed, otherwise falls back to cat.
$ sudo nx print knot.example.com ───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ File: /etc/nginx/sites-available/knot.example.com.conf ───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 1 │ server { 2 │ listen 443 ssl; 3 │ listen [::]:443 ssl; 4 │ server_name knot.example.com; 5 │ 6 │ ssl_certificate /etc/ssl/acme/example.com/fullchain.pem; 7 │ ssl_certificate_key /etc/ssl/acme/example.com/key.pem; 8 │ 9 │ access_log /var/log/nginx/example.access.log main; 10 │ 11 │ location / { 12 │ proxy_pass http://127.0.0.1:5555; 13 │ proxy_http_version 1.1; 14 │ 15 │ proxy_set_header Upgrade $http_upgrade; 16 │ proxy_set_header Connection $connection_upgrade; 17 │ 18 │ proxy_set_header Host $host; 19 │ proxy_set_header X-Real-IP $remote_addr; 20 │ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 21 │ proxy_set_header X-Forwarded-Proto $scheme; 22 │ } 23 │ } ───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Installation#
To install nx system-wide while keeping the source code in this repository for easy updates:
-
Move the repository to a permanent location (e.g., your home dir or a projects dir):
cd ~ git clone https://tangled.org/sullen.net/nx cd nx -
Make the script executable:
chmod +x nx -
Create a symbolic link in your PATH:
sudo ln -s $(pwd)/nx.sh /usr/local/bin/nx -
Ensure that your main Nginx config (e.g.,
/etc/nginx/nginx.conf) attempts to load in configurations at/etc/nginx/sites-enabled/*(or wherever you'd like to store your configurations).# ... http { # ... include /etc/nginx/sites-enabled/*; }
Usage#
Most commands require sudo to modify Nginx directories and reload the service.
NX - Nginx Site Manager
A simple utility to manage Nginx configurations.
USAGE:
nx <command> [arguments]
COMMANDS:
list, l List all sites. Supports --enabled or --disabled filters.
enable <site> Enable a site by creating a symlink.
disable <site> Disable a site by removing the symlink.
edit, e <site> Open site config in $EDITOR.
cat, print, p <site> Preview site config using batcat or cat.
EXAMPLES:
sudo nx list
sudo nx enable example.com
sudo nx disable pds.example.com
sudo nx e example.com
sudo nx print knot.example.com
ENVIRONMENT:
EDITOR Currently set to nano
NX_SITES_AVAILABLE_PATH Currently set to /etc/nginx/sites-available
NX_SITES_ENABLED_PATH Currently set to /etc/nginx/sites-enabled
NX_RELOAD_CMD Currently set to systemctl reload nginx
NX_TEST_CMD Currently set to nginx -t
Environment Variables#
The edit command respects your preferred editor. You can set this in your ~/.bashrc or ~/.zshrc:
export EDITOR='emacs'
Alternative sites-available and sites-enabled directories can be configured using the following
environment variables.
export NX_SITES_AVAILABLE_PATH=<preferred-path>
export NX_SITES_ENABLED_PATH=<preferred-path>
Alternative test and reload commands can be configured using the following environment variables. The following example demonstrates how this might look in a containerized context.
export NX_RELOAD_CMD='systemctl --user reload nginx'
export NX_TEST_CMD='podman exec nginx nginx -t'
Note: To ensure your environment variables are picked up when running with sudo, use the -E flag:
sudo -E nx enable example.com