File or directory for new virtual hosts - not working properly for Nginx

Trying to have the nginx generated vhost config files separate in the conf.d directory. I see the nginx virtualmin plugin has ""File or directory for new virtual hosts" option but when I select it, the new config file does get created in the directory but then I cannot edit it anymore because the file don't show up in the "edit configuration file" dropdown, nor does the new virtual host show up in the list under Nginx Web server.

Is this a bug or am I doing something wrong? BTW, I am on CentOS 7. Any help will be appreciated.

Thanks!

Status: 
Active

Comments

I found the issue. I had to add include /etc/nginx/conf.d/*; in the main nginx.conf file so that the virtual host files in the conf.d was read properly.

I think this line needs to be automatically added or deleted when the option "File or directory for new virtual hosts" is chosen in the module config. Maybe still a bug that needs fixing?

One more issue I found related to this. So, after creating the virtual domain, if I delete the virtual domain I get the following error:

Applying Nginx configuration .. .. configuration is invalid : nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/testingdomain.com.lock:2 nginx: configuration file /etc/nginx/nginx.conf test failed

This error only appears if "File or directory for new virtual hosts" option is selected to create the vhost files in a different folder rather than all the config files being added to the main nginx.conf file.

One more issue I found related to this. So, after creating the virtual domain, if I delete the virtual domain I get the following error:

Applying Nginx configuration .. .. configuration is invalid : nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/testingdomain.com.lock:2 nginx: configuration file /etc/nginx/nginx.conf test failed

This error only appears if "File or directory for new virtual hosts" option is selected to create the vhost files in a different folder rather than all the config files being added to the main nginx.conf file.

Make sure that your include path is /etc/nginx/conf.d/*.conf instead of just /etc/nginx/conf.d/* , so that .lock files aren't picked up.

That feature is really designed for use on systems (like Debian Linux) in which each domain has it's own config file by default, and thus already has the correct include line.

Mostafa's picture
Submitted by Mostafa on Tue, 10/11/2016 - 17:29

Thank you for your answer Jamie

I'm using Virtualmin on Centos 7. The problem is that virtualmin creates the separate config files without .conf extension. One can use the following command to include all files inside the conf.d folder except the .lock files:

include /etc/nginx/conf.d/*[!lock];

Which version of the Nginx plugin are you running there? You can see this in Virtualmin, on the "Features and Plugins" page.

The latest release should already be using .conf for per-domain Nginx config files.