A Virtualmin hook to generate a nginx server config file post-Apache server setup.
- You have a dedicated server or a VPS
- You have a LAMP stack beautifully set up and configured
- You use Virtualmin as the web hosting control panel of choice
- You have Apache proxied by a public-facing nginx, because performance
- You have to manually create and manage those nginx
.conf
files after setting up a host in Virtualmin, and - You
are too lazy for this shitfeel like your time can be used for something better
Virtualmin can be configured to run a command (hook) before and after making changes to a server. In the command context, a lot of global variables are pre-populated by Virtualmin, ready to use. For example:
uid=500
name=1
postgres=0
web_port=8000
limit_mysql=1
limit_ssl=0
Take a look at sample-dom-file
for a more complete example.
All of these variable names will be available with a $VIRTUALSERVER_
prefix, e.g. $VIRTUALSERVER_UID
, $VIRTUALSERVER_DOM
etc. Making use of them, we can write a shellscript to automate creating and managing the nginx config files on the fly.
Oh ok...
git clone [email protected]:phanan/virtualmin-nginx-config-hook.git
chmod +x virtualmin-nginx-config-hook/hook
Then, configure the post domain modification script to point to hook
's full path. Now whenever you create or modify a (sub)domain via Virtualmin interface, these things should happen, in that order:
- A file in the format of
{domain_name}.conf
is generated under{nginx_conf_dir}/sites-available
- A symbolic link pointing to said file is created under
{nginx_conf_dir}/sites-enabled
nginx
service is then reloaded and ready to serve
When you delete the (sub)domain, both the file and its symlink are removed.
The hook works with the assumption that your nginx is configured to read domain config files from sites-enabled
and sites-available
directories, following the (arguably) most common practice. Additionally, these variables can be configured to fit your needs:
NGINX_CONF_DIR="/etc/nginx"
NGINX_PORT=80
NGINX_SSL_PORT=443
Other than that... not so much, sorry.
- Upon Virtualmin domain update, the corresponding
.conf
file's content will be completely reset. If you have any custom modifications, they will be gone into oblivion. - Domain disabling and re-enabling are not supported yet.
MIT © Phan An.
This package is created and shared with hope that it may help someone out there, but its owner shouldn't take any responsibility for any claim, damages or other liability whatsoever. See LICENSE.