Summary of project:

Our website is an SaaS cloud application

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

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 and 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"; "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

However if a visitor attempts to access a sub-domain which does Not exist. Such as 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; 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 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

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

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 256
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 466 on July 09, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready