Ion Icon Ionnet.dev

NGX Commandline Tool

Category: Utility

# NGX Management Tool NGX is a bash CLI tool for managing NGINX on Linux It can be installed with a quick command OR installed with [Ion Package Manager](https://portfolio.ionnet.io/projects/3) It can be installed with: ``` wget -O - https://tools.ionnet.io/ngx_install.sh | sudo bash ``` Or first install IPM, which makes updating it easier in the future, as well as allowing to install other tools. ``` wget -O - https://tools.ionnet.io/ipm_install.sh | sudo bash ipm install ngx ``` To be able to create new site using NGX, you must create a template in `/etc/nginx/_templates` ``` mkdir -p /etc/nginx/_templates touch base # This will be the default template ``` Fill the new file with this content using an editor like `nano` or `vim` ``` server { listen 80; server_name {{server_name}}; root /var/www/vhosts/{{server_name}}; index index.html index.htm index.php; charset utf-8; location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_log /var/www/log/{{server_name}}/error_log error; access_log /var/www/log/{{server_name}}/access_log; sendfile off; fastcgi_intercept_errors on; #auth_basic "IonServer Restricted"; #auth_basic_user_file /var/www/vhosts/{{server_name}}/.htpasswd; #location / { # proxy_set_header X-Forwarded-For $remote_addr; # proxy_set_header Host $http_host; # proxy_pass http://localhost:<PORT>; #} #location ~ \.php { # fastcgi_pass unix:/run/php/php8.0-fpm.sock; # fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # fastcgi_param PATH_INFO $fastcgi_path_info; # fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; # fastcgi_read_timeout 600s; # fastcgi_send_timeout 600s; # fastcgi_index index.php; # include /etc/nginx/fastcgi_params; #} location ~ /\.ht { deny all; } } ``` You can now use `ngx new` to create a new site ``` ngx new example.com ``` It will ask you a few questions to make the new site You can always use `help` to see all the commands ``` ngx help ``` Help text: ``` Usage of ngx: list - Shows a list of all websites and their enabled/disabled status enable <SITE> - Enables the given website disable <SITE> - Disables the given website status <SITE> - Shows the enabled/disabled status of a single website edit <SITE> - Begin the editing of a website config and requests a reload when finished if any changes are made where <SITE> - Displays the full path to a website config new <SITE> [template] - Generates a new website config generate ... - Alias of "new" cert <SITE> - Request a certificate with LetsEncrypt on the given website new+cert ... - Alias of "new" followed by a "cert" restart - Restarts nginx reload - Reloads nginx update-self - Updates this tool using wget ``` [https://tools.ionnet.io/](https://tools.ionnet.io/)