Sandeep explained how to do it using NGINX. Additionally, you can
- do that with DNS entries (maybe for your personal site)
- do so by having a webserver (Apache, NGINX, Node.JS, IIS,...) route different subdomains to different controllers
- using a generic controller which takes the subdomain as an input parameter to retrieve a user and their content (Node.JS, Tomcat, Django,...)
However, only the third (and in special cases the second, see Sandeep's answer) option will enable you to generically have subdomains without service-interruptions.