NGINX - switch from one global config to seperate files


for nginx options it is possible to choose on “File or directory for new virtual hosts” between writing everything into the main config file (which seems to be the default) or to write into per host config files (/etc/nginx/sites-available).

This is my prefered way, after i found it out :slight_smile:

Is there any way to switch from global config file to the sites-available if there are already sites on the server?
Like rewriting all of the config files?

And a side question, can i use placeholders in “Additional Nginx directives for new virtual hosts” like
include /home/%vhost%/etc/nginx_site.conf


Noone has an update for me? :slight_smile:

I am pretty sure there is a way to rewrite the config files - if not - i would say this feature is missing!

yes, its possible.
Go to webmin > Servers > Nginx webserver and select the module config. There you will have

File or directory for new virtual hosts (add /etc/nginx/sites-available as the value)
Directory for links to new virtual host files (add /etc/nginx/sites-enabled as the custom value)

Yes - thanks for your answer - but that does NOT rewrite existing domains :frowning:

Disabling the website feature and re-enabling it for the domain should re-generate it in the separate file. But, be careful with that, if you have any customizations in the config file made outside of Virtualmin. It’s possible to script that using the command line interface, as well, if you have a lo of domains you want to do this for.

The command line way to do that quickly for all of your domains:

# virtualmin disable-feature --all-domains --web # virtualmin enable-feature --all-domains --web

But, again, be careful! That’ll lose custom web configurations that aren’t reflected in your Server Templates.

Trying that i ran into a desaster even tho i made a backup.

This is not going to work.

One thing would be to manually split it - but that would be a pain in the back as well :frowning:

Noone with a good idea?

How many different websites do you have in that nginx config file? Up to about 15–20, just split it with a text editor. Much more than that, write a little script that does the split for you. For example, ask Google [perl script to split a large text file].