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:
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_ACTION" = "CREATE_DOMAIN" ]; then
if [ "${VIRTUALSERVER_WEB}" = "1" ];
then
cp /etc/nginx/sites-available/template.conf $NGINX_CONF_FILE
sed -e 's#{DOM}#$VIRTUALSERVER_DOM#' $NGINX_CONF_FILE
sed -e 's#{SITE_IP}#$VIRTUALSERVER_IP#' $NGINX_CONF_FILE
sed -e 's#{HOME}#$VIRTUALSERVER_HOME#' $NGINX_CONF_FILE
ln -s $NGINX_CONF_FILE /etc/nginx/sites-enabled/${VIRTUALSERVER_DOM}.conf
/etc/init.d/nginx reload
fi
fi
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:
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:
As:
I do need to create the NGINX-Files manually for the new VirtualServer by the PostDomain-Hook,
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…
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.
Template-File
Regarding to the invisible template.conf in etc/nginx/conf.d … it contains only this:
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.
@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 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 1.1.1.1 and apache 2.2.2.2 ?
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.
Ok, I see what you mean:
I do have to manually configure nginx to only listen on ports 80 & 443 at 1.1.1.1, and apache on 80 & 443 on 2.2.2.2.
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 1.1.1.1 is only usable for nginx, and 2.2.2.2 for apache.
If I do a mistake here (e.g. choose IP 1.1.1.1 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 127.0.0.1 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.