Is there any soft / hard limit on the number of virtual hosts that Nginx can handle?

And what are performance implications? Is it practical to host tens of thousands of vhosts on one Nginx instance? How much would the increased latency be?

We plan to offer custom domains for users, and to assign different chroot per user and to serve static assets like js/css directly from nginx, we want to host as many users per nginx instance as possible.


Solution 1:

If you don't require dynamic content, fastcgi daemons etcetera, unlimited vhosts can be as simple as this SF answer.

server_name *.dom.tld;
root /var/www/$http_host/public;

In that case, your first bottleneck will likely be the filesystem, not Nginx.

Also note that major reverse proxies such as Cloudflare use (a modified version of) Nginx, so it sounds plausible to do.