3

As per the requirement for our platform, Every website will be auto-hosted along with DNS configurations, making the site live on domain booked, configuring Nginx for each domain and subdomain.

We need to have dynamic virtual hosts configurations for Nginx, so we came up with three options, mentioned below.

Need suggestion which one will be a right choice, as our website base is growing with 30 to 40 new websites per day and there are already 2000+ websites registered on the platform.

Any better option other than these will also be considered.

Mass Virtual Hosts Configurations

This can be achieved by making server_name dynamic using regex.

Pros:

  • Single file, single virtual hosts.
  • No need to reload Nginx for every new domain registration.
  • Can incorporate any number of domains.

Cons:

  • Can lead to a DDoS attack if someone finds out that server is processing any domain request coming to it.
  • Can slow down response, as for every request database query will be performed to verify whether domain/subdomain exists with the platform.

Ways to overcoming issue:

  • Caching like Memcache or Redis can be used to cache all the domains and subdomains, so there will be few database queries to check domain and subdomain existence (only in case of cache failure)
  • Using Cloudflare, which can help us with DDoS prevention.
  • Nginx can also be configured to block requests for certain IPs which send requests too often.
  • Certain Ip addresses and bots responsible for any kind of attack can also be blocked using bad bot blocker configurations.

Individual Virtual Hosts file configurations

A script, which on receiving a request for the new domain, will create virtual hosts in a separate file, make it available for Nginx, enable it and reload Nginx.

Pros:

  • Separate Virtual Hosts for each new domain registered.
  • Allows only registered domains to be processed.

Cons:

  • Need to trigger script for every new domain registered, which will be run as sudo user/root user
  • Can lead to 1000+ files which need to be loaded by Nginx and processed.
  • For every new virtual host, Nginx needs to be reloaded.
  • Request handling and managing might become a hassle if too many domains are registered.

Ways to overcome issue:

  • Instead of multiple files, use a single file for all virtual hosts.

Single File multiple hosts configurations

A script, which on receiving a request for the new domain, will append new virtual hosts in the single file used by Nginx and reload Nginx.

Pros:

  • Separate virtual hosts for each new domain registered.
  • Allows only registered domains to be processed.
  • Reduces the number of files for all virtual hosts to one.

Cons:

  • The file can become heavy because of too many virtual hosts entries.
  • Can slow down Nginx processing because of a number of virtual hosts to look from.
  • For every new virtual host, Nginx needs to be reloaded.

Ways to overcome issue:

  • Have No other solution than having mass virtual hosts.
0

We finally have settled on

Individual Virtual Hosts file configurations

Reason being, Most of the websites registered on our platform are served via subdomain and very few will have their own domain. So, in this case, single file with wildcard entry will serve the purpose for the majority of the websites. And for few websites with their own domain, we can have separate host file and this can be automated.

This also helps in serving https requests for each subdomain as well as domain. We can also automate few things on nginx server by using Lua scripts to manage these hosts files.

If anyone has any better option please reply with your comments, it will help us a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.