2

I am assuming that there is not someone at hubpages.com adding ServerAlias manually to make subdomains work.

I want to do something similar with Wordpress but I have a hard time grasping the concept of how it works.

From my understanding you need DNS for subdomains to work properly and you need to add a vhost.

I searched stackoverflow for "fake subdomain" creation, but usually the answer is "vhost". Is there a way then to auto-create vhosts for a nonexistent subdomain?

mashup
  • 237
  • 2
  • 12
  • Found this comment on another question useful: http://stackoverflow.com/a/9241943/485483 – mashup Mar 31 '13 at 07:14
  • you might want to checkout hipache. It does what you are asking for really easily. checkout this answer: http://serverfault.com/a/624877/239954 – AnandKumar Patel Aug 29 '14 at 05:48

2 Answers2

2

The DNS part is done using a wildcard DNS record:

*.hubpages.com.     900 IN  A   66.211.109.24

The server part is probably done using an automated system to create vhosts when users sign up.

Barmar
  • 741,623
  • 53
  • 500
  • 612
2

This is done with a wildcard DNS entry to get the domains to reach the webserver.

Once at the webserver, there's a few techniques you can use with Apache

mod_vhost_alias

mod_vhost_alias allows you dynamically map the virtual hostname onto a document root.

This is a good technique when you want to serve different codebases for different domains, and you have the means to dynamically configure them. I've used this technique to automatically deploy git branches of code by having a custom 404 handler deploy them on demand.

fallthrough to default VirtualHost

Alternatively, rely on the fact that an 'unknown' hostname will fall through to the first defined vhost, then you simply have the application on that host self-configure itself for the supplied domain. I used to run pastebin.com, and this is how I did it there.

This technique is good when the codebase for each domain is identical, only the configuration needs to change.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348