Welcome! Log In Create A New Profile

Advanced

Setup Nginx server only for sub-domain virtual hosts with custom error page for unknown sub-domains.

Posted by anagio 
Summary of project:

Our website is an SaaS cloud application

The main website front end www.example.com runs wordpress. When users register for an account we will need to create a virtual host for the user, so they can login at username.example.com

The server which will manage all sub-domain virtual hosts will be Nginx.

I was told that Nginx can be configured without a default virtual host, see below

"You just dont setup the main domain as an nginx vhost on the subdomain server and leave the dns pointing at the old server. You then setup vhosts for the subdomains (or catch all subdomains depending on your application) and point dns at your subdomain server"

So I will have some A records going to example.com and www.example.com which is run one one server IP. And for the sub-domain Nginx server it will have another IP.

To setup all sub-domain to map to our application folder I was told to do the following

map $http_host $subdir {
hostnames;
.foo.bar.com "foo";
.baz.bar.com "baz";
}

server {
root /path/to/$subdir;

}

So each new user we will add an entry into this config file and do nginx -s reload

Our DNS for the sub-domain server I am not sure how to setup it should have a wild card so that we do not have to create A records for each sub-domain right? Please tell me your thoughts about this method of creating sub-domains and handling DNS.

Now if that is correct user can login to username.example.com

However if a visitor attempts to access a sub-domain which does Not exist. Such as asdfasdf.example.com I would like to have them redirected to a custom 404 page, on the nginx server.

The main requirements are
Sub-domains for users ie; username.example.com are the ones which are accessible
Any access to sub-domains that do not exist (no username for that sub-domain) should go to custom 404 page.
No default virtual host because this server has one IP and main domain www.example.com is running on another IP.
Suggest to us the best way to create virtual hosts on Nginx for each user account
Suggest best method to handle DNS

We will setup the nginx server on Amazon ec2 and provide access

Thank you
Hello,

Please write to me at loco@andrews.lv if interested and I'll be happy to help you out.

Andrejs
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 99
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready