Been playing with nginx for about an hour trying to setup mass dynamic virtual hosts. If you ever done it in apache you know what I mean.
Goal is to have dynamic subdomains for few people in the office (more than 50)
Been playing with nginx for about an hour trying to setup mass dynamic virtual hosts. If you ever done it in apache you know what I mean.
Goal is to have dynamic subdomains for few people in the office (more than 50)
Another alternative is to have includes a few levels deep so that directories can be categorized as you see fit. For example:
As long as you are comfortable with scripting, it is not very hard to put together some scripts that will quickly set up vhosts in nginx. This slicehost article goes through setting up a couple of vhosts and does it in a way that is easily scriptable and keeps the configurations separate. The only downside is having to restart the server, but that's to be expected with config changes.
Update: If you don't want to do any of the config maintaining yourself, then your only 2 options (the safe ones anyways) would be to either find a program that will let your users manage their own chunk of their nginx config (which will let them create all the subdomains they want), or to create such a user-facing management console yourself.
Doing this yourself would not be too hard, especially if you already have the scripts to do the work of setting things up. The web-based interface can call out to the scripts to do the actual work so that all the web interface has to deal with is managing who has access to what things.
You will need some scripting knowladge to put this together, i would use php, but if you are good in bash scripting use that. I would do it like this:
First create some folder (/usr/local/etc/nginx/domain.com/).
In main nginx.conf add command : include /usr/local/etc/nginx/domain.com/*.conf;
Every file in this folder should be different vhost names subdomain.conf.
You do not need to restart nginx server for config to take action, you only need to reload it : /usr/local/etc/rc.d/nginx reload
OR you can make only one conf file, where all vhosts should be set. This is probably better so that nginx doesn't need to load up 50 files, but only one....
IF you have problems with scripting, then ask question about that...
As @Samuurai suggested here is a short version Angular 5 with nginx build integration:
Perhaps doing this will get you where you want to be:
I like this as I can literally create sites on the fly, just create new directory named after the domain and point the DNS to the server ip.
Based on user2001260's answer, later edited by partlov, here's my outcome.
Bear in mind this is for a dev server located on a local virtual machine, where the
.dev
prefix is used at the end of each domain. If you want to remove it, or use something else, the\.dev
part in theserver_name
directive could be edited or altogether removed.}
The regex in
server_name
captures the variablessubdomain
anddomain
. Thesubdomain
part is optional and can be empty. I have set it so that by default, if you have a subdomain, sayadmin.mysite.com
the root is set to the same root asmysite.com
. This way, the same front-controller (in my caseindex.php
) can route based on the subdomain. But if you want to keep an altogether different application in a subdomain, you can have aadmin.mysite.com
dir and it will use that directory for calls toadmin.mysite.com
.Careful: The use of
if
is discouraged in the current nginx version, since it adds extra processing overhead for each request, but it should be fine for use in a dev environment, which is what this configuration is good for. In a production environment, I would recommend not using a mass virtual host configuration and configuring each site separately, for more control and better security.