Submitted by kindnation on Thu, 03/20/2014 - 22:54
After you create a virtual server with Nginx, the server block needs an "include" at the end, so Nginx is able to load additional configs for that server. You can use the already existing one that is commented out
include /etc/nginx/conf.d/*.conf;but it needs to be put at the end of the server block.
Image attached for reference
Status:
Closed (fixed)
Comments
Submitted by JamieCameron on Sat, 03/22/2014 - 00:54 Comment #1
You can configure the Virtualmin Nginx module to add custom directives to new server blocks. This can be done at System Settings -> Features and Plugins, by clicking on Configure next to Nginx and filling in the "Additional Nginx directives for new virtual hosts" field.
Submitted by kindnation on Sat, 03/22/2014 - 05:33 Comment #2
awesome thanks Jamie!
Submitted by kindnation on Sat, 03/22/2014 - 06:12 Comment #3
Jamie,
When using the Nginx directives, I found a bug when I used the "File or directory for new virtual hosts", which does work for Virtual Server creation, but when you delete the server it leaves the server in the directory without deleting it like it's supposed to.
Submitted by kindnation on Sat, 03/22/2014 - 08:53 Comment #4
to fix, I have to add:
include /etc/nginx/sites/*;
in the main nginx.conf
Now, it deletes the virtual server from the directory as expected, however I do get an error:
Applying Nginx configuration .. .. configuration is invalid : nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/sites/nikanti.net.lock:2 nginx: configuration file /etc/nginx/nginx.conf test failed
I'm not sure if this is related, but I tried to disable the "Test new configuration before saving?" in Webmin > Servers > Nginx Webserver > Edit Configuration Files, but after saving, it doesn't disable.
This is only a minor bug as it's only a warning, but it might confuse a hosting customer.
Submitted by JamieCameron on Sat, 03/22/2014 - 13:51 Comment #5
Change your include line to :
include /etc/nginx/sites/*.conf;
that will make it skip any
.lock
files that Virtualmin creates.Submitted by kindnation on Sat, 03/22/2014 - 15:56 Comment #6
The problem here is that the sites are stored as their domain names in the directory:
domain1.com domain2.net etc.
so include /etc/nginx/sites/*.conf; doesn't work. It would only work if I stored all the sites within a single sites.conf file though, but having each server with their own config file is better organized.
Submitted by kindnation on Sat, 03/22/2014 - 23:04 Comment #7
here's a fix, in case anyone else want to store servers in directories as separate files. I just created a few includes for each tld I want to support:
include /etc/nginx/sites/.com; include /etc/nginx/sites/.net; include /etc/nginx/sites/.org; include /etc/nginx/sites/.th; include /etc/nginx/sites/*.de;
etc, etc.
Submitted by kindnation on Sun, 03/23/2014 - 23:49 Comment #8
After testing, it doesn't work properly because it puts the directives in the wrong place.
For example, I need to include:
location / { try_files $uri $uri/ /index.php?$args; }
Which allows Nginx to do pretty permalinks in WordPress. The location of the directives needs to happen after:
location ~ .php$ { try_files $uri =404; fastcgi_pass unix:/var/php-nginx/139563233210424.sock/socket; }
Submitted by JamieCameron on Mon, 03/24/2014 - 00:23 Comment #9
So you need a way to insert directives into the default
location
block for.php
that Virtualmin creates? Unfortunately we don't have a way to configure that yet, sorry.Submitted by kindnation on Mon, 03/24/2014 - 00:28 Comment #10
Jamie,
All that it needs is:
include /etc/nginx/conf.d/*.conf;
exactly where I showed you in the pic. That will load the various directive files needed, exactly how it's supposed to work.
Or you can move the insertion of the directives at the end, instead of inserting it at the very beginning.
Submitted by kindnation on Mon, 03/24/2014 - 00:49 Comment #11
For reference:
http://codex.wordpress.org/Nginx
The nginx wordpress directives have to be added at the end, in their example they are using:
include sites-enabled/*;
It has to be included in the server block, but at the end of the file. It won't work inserting the directives before the:
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/php-nginx/139563233210424.sock/socket;
}
Submitted by kindnation on Mon, 03/24/2014 - 02:04 Comment #12
You can see in the picture, highlighted in red, that the directives are being inserted into the wrong place. It doesn't make sense to add the directives here.
I mentioned where the directives have to be inserted since the very first post. If it's inserted where Virtualmin currently does, Nginx will fail to restart. If you insert the directives at the end, it works like it's supposed to.
Submitted by JamieCameron on Mon, 03/24/2014 - 22:12 Comment #13
Unfortunately, Virtualmin doesn't necessarily know what the correct ordering should be for those custom directives - it just inserts them after the first set of default lines.
Instead of adding your custom settings this way, a better option may be to write a small script that gets called after a domain is created to add the directives - see https://www.virtualmin.com/documentation/developer/prepost
Submitted by kindnation on Mon, 03/24/2014 - 22:44 Comment #14
Thanks, didn't know there was an option to do that. I'll give it a try.
Submitted by kindnation on Thu, 05/15/2014 - 08:23 Comment #15
Forgot to update that I got it working. Thanks Jamie.
You can use the following directive to include all files inside the conf.d folder except the .lock files:
include /etc/nginx/conf.d/*[!lock];