Pre and Post Domain Modification Scripts - empty ${VIRTUALSERVER_DOM} - how to debug?

I have a script that is used for Post-Domain-Modification.

It use the Variable ${VIRTUALSERVER_DOM}, but this is empty if the script runs (see following image):

How can that happen?
The current Task I’ve executed was to change the server-ip.

The Documentation-Page described that this variable should exist… so why does it not work.
Is there an issue from my side?

Pre and Post Domain Modification Scripts – Virtualmin


Try quoting the path that is getting deleted, like rm "/etc/nginx/sites-enabled/${VIRTUALSERVER_DOM}.conf". Also, in paths sites-enabled all files should be symlinks to sites-available, so no reason for deleting twice. Furthermore, you shouldn’t do anything like that, as Virtualmin will automatically clean all of those files. Probably, you should look at Servers ⇾ Nginx Webserver ⇾ Configurable options page.

How to debug?

You should make your script to dump all env variables, and later check on what you get set:

printenv > /root/all-env

Hey @Ilia,
thanks for your response. The debugging-hint helps a lot - even for future testings.

I got it to work by changing the script to use sed instead of perl command.

    if [ "${VIRTUALSERVER_WEB}" = "1" ];
        cp /etc/nginx/sites-available/template.conf $NGINX_CONF_FILE
        ln -s $NGINX_CONF_FILE /etc/nginx/sites-enabled/${VIRTUALSERVER_DOM}.conf
        /etc/init.d/nginx reload

Thanks so far.

Now I have to check, how I can handle the SSL-Certifications in right way with auto-generating via letsencrypt and putting it into NGINX & Apache.

@Ilia I have another issue… and like to ask if this is a planed behavior or a bug.

I do have create a file /etc/nginx/sites-available/template.conf. But If I look into NGINX - Config-Section I see all other files, but not the template.conf in /sites-available:

That file should have parseable syntax to be picked up, considering /etc/nginx/lists is being already included.

Why are you creating issues for yourself? None of this is needed, as must be done automatically by Virtualmin! Is there a reason why you’re doing this at the first place?

I would love to have this handled by virtualmin itself, but I’m not sure if it does. Let me explain why I think so:

I know everything work as you described if I do install an Nginx-only Virtualmin. In that case the host-files are created for Nginx and work as expected - even with letsencrypt.

But at my environment I have a Apache-Virtualmin Setup and add installed NGINX additionally later on that server. That means: If I create a new VirtualServer, only the Apache-Vhost-File is created, but not the Nginx-VHost-Files.

What I do meant before by “finding a way for letsencrypt & ssl” is the following:

  1. I do need to create the NGINX-Files manually for the new VirtualServer by the PostDomain-Hook,
  2. and Nginx is listening at Port 443 (means he handles the https-requests first)

I do need to configure nginx that way to listening on 443. That Maens I must have an existing ssl-certificate…

    ssl_certificate /home/myDomain/ssl.combined;
    ssl_certificate_key /home/myDomain/ssl.key;

If I don’t have this entries and a valid cert & key for it, nginx quit with an error.

My note was about that I have to see, how I could handle the workflow from "activating SSL-Domain over requesting let'sEncrypt certificate till assigning them also in NGinx - like it’s automatically added to apache` in a clean way to not “crash” nginx.

If there a way to have this for NGINX automatically working, please give me a hint. Didn’t found how to make this work in another way the one I’ve found and describe above.


Regarding to the invisible template.conf in etc/nginx/conf.d … it contains only this:

So I don’t see, why it’s not listed in the Pulldown of the Config-Section.

Do you have multiple dedicated IPs used on per-domain basis? If so, I think it could be possible to use two different web-servers listening on different specific IP addresses, but you would need to also manually install webmin-virtualmin-nginx* packages and enable Nginx support in System Settings ⇾ Features and Plugins page. Later then it should be possible to pick which web-server to use for which domain (upon creation), and none of those manual steps would be required.

1 Like

@Ilia oh, with System Settings -> Features is a good hint. Didn’t mention about that section.
For webmin-virtualmin-nginx it seems I’ve already installed it that way, as my features-overview look like that:

So I activated both Nginx entries now for testing purposes and create a new Virtualhost to test it.

And yes, - partial - success, I can choose on VirtualServer creation which Webserver to choose:

So what’s now missing is the thing you noticed about the “multiple dedicated IP’s”, because for sure NGINX & Apache can not listen at the same IP:PORT at the same time.

Do you have some information for me, how to set it up in a solid way, that nginx have ip and apache ?

Would be awesome if I could pre-configure that in any way to a ServerConfigurationTemplate or AccountPlan… So I only need to name it “1GB Apache” or “1GB NGinx” and I would know which kind of Webserver would be used for the current account.

  1. Check that neither Apache nor Nginx listen on all addresses
  2. Use IP address and forwarding accordion on Create Virtual Server page to setup private IP for given virtual server

For that purpose use System Settings ⇾ Account Plans page.

Ok, I see what you mean:
I do have to manually configure nginx to only listen on ports 80 & 443 at, and apache on 80 & 443 on

But that means I do have to choose the right IP everytime I do create a new Webspace, right?
So I have to know, that is only usable for nginx, and for apache.

If I do a mistake here (e.g. choose IP and use “Apache-AcountPlan” it fail.

Does I understand this in the right way, or do I missed something.

I think you could make Apache and Nginx to only listen on by default, and Virtualmin when adding a virtual server will automatically set it up for the specific private IP.

@Ilia OK, I think I better remove Apache and only go with Nginx.
Tried lots of hours to get it work in a smooth way, but there are to many race-conditions in many cases (e.g. if mixing up ip’s for those both webservers, etc.)

Can you give me a hint, how to remove Apache in a clean way from this server and only keep nginx on it?

Apache is part of the stack. The easiest way is just to stop it and disable it. If you remove it ignoring dependencies the package manager could start misbehave or complain.

The safest would be just disable and mask Apache service using systemctl command.

Later on, you should disable it in Virtualmin on Features and Plugins page as well.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.