A simple utility to manage Nginx configurations.

Add ability to customize sites-available and sites-enabled dirs

+34 -21
+27 -16
README.md
··· 50 50 51 51 Most commands require sudo to modify Nginx directories and reload the service. 52 52 53 - - List sites: sudo nx list (or nx l) 54 - - Enable site: sudo nx enable mydomain.com 55 - - Disable site: sudo nx disable mydomain.com 56 - - Edit config: sudo nx e mydomain.com 57 - - Print config: nx p mydomain.com 58 - 59 53 ```bash 60 54 NX - Nginx Site Manager 61 55 ··· 65 59 nx <command> [arguments] 66 60 67 61 COMMANDS: 68 - list, l List all sites. Supports --enabled or --available filters. 69 - enable <site> Enable a site by creating a symlink. 70 - disable <site> Disable a site by removing the symlink. 71 - edit, e <site> Open site config in $EDITOR. 72 - cat, print, p <site> Preview site config using batcat or cat. 62 + list, l List all sites. Supports --enabled or --available filters. 63 + enable <site> Enable a site by creating a symlink. 64 + disable <site> Disable a site by removing the symlink. 65 + edit, e <site> Open site config in $EDITOR. 66 + cat, print, p <site> Preview site config using batcat or cat. 73 67 74 68 EXAMPLES: 75 69 sudo nx list 76 - sudo nx enable mydomain.com 77 - sudo nx e mydomain.com 70 + sudo nx enable example.com 71 + sudo nx disable pds.example.com 72 + sudo nx e example.com 73 + sudo nx print knot.example.com 78 74 79 75 ENVIRONMENT: 80 - $EDITOR: Currently set to nano 76 + EDITOR Currently set to nano 77 + NX_SITES_AVAILABLE_PATH Currently set to /etc/nginx/sites-available 78 + NX_SITES_ENABLED_PATH Currently set to /etc/nginx/sites-enabled 81 79 ``` 82 80 83 81 ## Environment Variables 84 82 85 83 The edit command respects your preferred editor. You can set this in your ~/.bashrc or ~/.zshrc: 86 84 85 + ```bash 87 86 export EDITOR='emacs' 87 + ``` 88 88 89 - Note: To ensure your personal $EDITOR setting is picked up when running with sudo, use the -E flag: 90 - sudo -E nx e mydomain.com 89 + Alternative sites-available and sites-enabled directories can be configured using the following 90 + environment variables. 91 + 92 + ```bash 93 + export NX_SITES_AVAILABLE_PATH=<preferred-path> 94 + export NX_SITES_ENABLED_PATH=<preferred-path> 95 + ``` 96 + 97 + Note: To ensure your environment variables are picked up when running with sudo, use the -E flag: 98 + 99 + ```bash 100 + sudo -E nx enable example.com 101 + ``` 91 102 92 103 ## License 93 104
+7 -5
nx
··· 1 1 #!/bin/bash 2 2 3 3 # Configuration 4 - AVAILABLE="/etc/nginx/sites-available" 5 - ENABLED="/etc/nginx/sites-enabled" 4 + AVAILABLE=${NX_SITES_AVAILABLE_PATH:-/etc/nginx/sites-available} 5 + ENABLED=${NX_SITES_ENABLED_PATH:-/etc/nginx/sites-enabled} 6 6 ACTION=$1 7 7 SITE=$2 8 8 ··· 140 140 141 141 ${BOLD}EXAMPLES:${NC} 142 142 sudo nx list 143 - sudo nx enable mydomain.com 144 - sudo nx e mydomain.com 143 + sudo nx enable example.com 144 + sudo nx e example.com 145 145 146 146 ${BOLD}ENVIRONMENT:${NC} 147 - \$EDITOR: Currently set to ${BOLD}${EDITOR:-nano}${NC} 147 + EDITOR Currently set to ${BOLD}${EDITOR:-nano}${NC} 148 + NX_SITES_AVAILABLE_PATH Currently set to ${BOLD}${AVAILABLE}${NC} 149 + NX_SITES_ENABLED_PATH Currently set to ${BOLD}${ENABLED}${NC} 148 150 EOF 149 151 )" 150 152 exit 1