NGINX config structure for provisioning virtual hosts with a CLI tool
This is a proposal for a new NGINX config structure that allows for provisioning virtual hosts with a CLI tool. Please keep in mind that this is a proof of concept and the actual config files in the example nginx config directory are not complete. It is the minimum viable product to demonstrate the CLI tool rather than a complete NGINX config.
All you need is docker installed with the docker compose plugin.
On your host machine, run the following commands:
docker compose up -d
docker compose exec nginx bash
Once you are inside the docker container, you can create some virtual hosts:
vhost create catch-all default-backend
vhost enable default-backend
vhost create wordpress my-blog domain_names=wordpress-127-0-0-1.nip.io
vhost enable my-blog
vhost create magento-2 my-store magento_version=2.4.6.3 domain_names=magento-127-0-0-1.nip.io
vhost enable my-store
Finally you can reload nginx to apply the changes:
nginx -s reload
That's it! You can now visit the following URLs:
http://localhost
http://wordpress-127-0-0-1.nip.io
http://magento-127-0-0-1.nip.io
Debian
curl -sL -o ./vhost_0.0.4_amd64.deb https://github.com/null93/vhost/releases/download/0.0.4/vhost_0.0.4_amd64.deb
sudo dpkg -i ./vhost_0.0.4_amd64.deb
rm ./vhost_0.0.4_amd64.deb
curl -sL -o ./vhost_0.0.4_arm64.deb https://github.com/null93/vhost/releases/download/0.0.4/vhost_0.0.4_arm64.deb
sudo dpkg -i ./vhost_0.0.4_arm64.deb
rm ./vhost_0.0.4_arm64.deb
Red Hat
rpm -i https://github.com/null93/vhost/releases/download/0.0.4/vhost-0.0.4-1.aarch64.rpm
rpm -i https://github.com/null93/vhost/releases/download/0.0.4/vhost-0.0.4-1.x86_64.rpm
Alpine
curl -sL -o ./vhost_0.0.4_aarch64.apk https://github.com/null93/vhost/releases/download/0.0.4/vhost_0.0.4_aarch64.apk
apk add --allow-untrusted ./vhost_0.0.4_aarch64.apk
rm ./vhost_0.0.4_aarch64.apk
curl -sL -o ./vhost_0.0.4_x86_64.apk https://github.com/null93/vhost/releases/download/0.0.4/vhost_0.0.4_x86_64.apk
apk add --allow-untrusted ./vhost_0.0.4_x86_64.apk
rm ./vhost_0.0.4_x86_64.apk
Arch
curl -sL -o ./vhost-0.0.4-1-aarch64.pkg.tar.zst https://github.com/null93/vhost/releases/download/0.0.4/vhost-0.0.4-1-aarch64.pkg.tar.zst
sudo pacman -U ./vhost-0.0.4-1-aarch64.pkg.tar.zst
rm ./vhost-0.0.4-1-aarch64.pkg.tar.zst
curl -sL -o ./vhost-0.0.4-1-x86_64.pkg.tar.zst https://github.com/null93/vhost/releases/download/0.0.4/vhost-0.0.4-1-x86_64.pkg.tar.zst
sudo pacman -U ./vhost-0.0.4-1-x86_64.pkg.tar.zst
rm ./vhost-0.0.4-1-x86_64.pkg.tar.zst