Nginx - changing Default root directory breaks Virtualmin

I just changed the document root of a virtual host running with nginx

When I want to look back at the options on the same page (virtualmin-nginx/edit_server.cgi) it says Virtual host no longer exists!. The error remains when I add back the old path in the site config file.

SYSTEM INFORMATION
OS type and version Ubunto 24.04
Webmin version 2.402
Virtualmin version 7.30.8
Webserver version 1.24.0

Have you run recheck config (and restart webmin of cause)
If you have backups you may need to restore last one.

Ok, I see what you did go to webmin and the nginx webserver and locate the server you added the root document and correct using Document Location and restart nginx server

How did you change the document root?

I think he did it here, point to /var/www/html/

and it will respond with

Is this expected?

I copied all the files from standard public_html to /var/www/html and it shows ok on a webpage, just the virtualmin clicking Configure Nginx Website responds with Virtual host no longer exist.

Got it to work by adding a root path the the well-known url path (was try to get request cert to work)

Also cert request works on all names except admin and and webmail

I changed it through the menu in the domain virtualmin Configure Nginx Website > Document Options.

The path I changed is another path in the home user. /home/user/htdocs/ After I did this the files were correctly served. One thing I could check though is that php files are not served and return a 404.

And thanks for the help stefan1959. I could realise that the server document root could be edited back from the Webmin > Servers > Nginx Webserver. This avoids to have to ssh to change it back.

This is a good point. I did this too but the Nginx configuration pages on Virtualmin are still showing Virtual host no longer exists!

I also did it for the php directive and this was not sufficient to make php work.

In the Nginx configuration file I saw that there was this line under the root directory definition:

	fastcgi_param SCRIPT_FILENAME "/home/test/public_html$fastcgi_script_name";

When I manually change the path there and restart Nginx, I finally get php to work. But I still can’t get to edit the nginx configuration from the Virtualmin side.

Worked for me, did you restart nginx webserver?

I have to admin I don’t remember if I did.
When I test it now, I see that the problem disappears when you change again the path on the Webmin part and this without restating nginx.

Don’t do it! There’s no practical need, and it can’t be done just like that anyway.

1 Like

WM/VM helps you set up a server quickly in an integrated and tested fashion and then helps you manage it. It is NOT the system administrator.

That said, if the software offers to let you easily change the root directory, then it is expected to work. What we don’ t know is if the OP got any error messages and if they had the proper permissions to the new path.

I happen to have practical need for it. Furthermore, when I do it, the website is served as expected.

Only Virtualmin is broken at this particular page. Even Webmin handle this simple change.

I can also add that I have done this in the past with Virtualmin 7.10.0 and the Apache server and this was not breaking anything. I don’t know if this comes from the fact that it is nginx or a new version of Virtualmin.

Quite possibly. Nginx is definitely NOT Apache and only one or the other should ever be tried never try to do both or any combination thereof. this server was server setup was with the -LEMP option? and not gone through some previous incarnation?

It would appear that th OP is editing webmin source code to mask whatever they are trying to do, he points out that his edit works on both, but @Ilia is correct in that fact that webmin source code shouldn’t be edited and a bug should be raised or the correct method used to achieve the goal.

@Stegan as I said, in te pas I used a Virtualmin 7.10.0 with LAMP and renaming document root on Apache was not a problem

Now I am trying Virtualmin 7.30.8 LEMP and renaming document root breaks the Virtualmin interface even though the change is taken into account an all the rest works fine.

@jimr1 I haven’t modified Webmin sourse code. Only I changed this :

And I get this:

1 Like

Yeah, that’s bug-like.

@Jamie why would the document root effect Virtualmin finding the virtual host?

The issue is that when we change the document root in the module, the Virtualmin menu and the redirect from the return page weren’t updated. This patch fixes it.

However, @Jamie, that’s not all. We also need to update other paths inside the Nginx domain config and the Virtualmin domain config like we do on the “Website Options” page.

@aloxe Try applying this patch to see if it fixes the issue for you:

webmin patch https://github.com/virtualmin/virtualmin-nginx/commit/fce98e5

@Jamie, we should use set_public_html_dir API in that update too. However, it won’t be possible anymore to set any path on the system; it will have to be under the user’s home directory, which is probably what we want to do unless we consider that the Virtualmin Nginx module can be used completely outside of Virtualmin.

Let me know what you think and how you think it should be designed. I suggest we make the “Web Configuration ⇾ Configure Nginx Website: Document Options” page show the document root directory name relative to the user’s home and use that when checking and parsing upon saving.

Patch failed: Hmm… Looks like a unified diff to me…

Anyway, I applied the change manually. While this doesn’t solve the error on virtual servers that already have a modified document root, the bug doesn’t show any more when I modify the document root of a fresh virtual server.

Thanks @Ilia for this quick response and good luck with the rest of the fix.