You can use a specific DNS record ( CNAME or A / AAAA ) for each known subdomain or a wild-card DNS record that will accept * .example.com:
$ORIGIN example.com foo IN A 12.34.6.78 bar IN A 12.34.6.78
or
$ORIGIN example.com * IN A 12.34.6.78
The advantage of the latter is that after the service is started, no DNS or Apache configuration changes are required. The disadvantage is that all such wildcards must (by definition) return the same IP address.
Apache configuration will depend on your requirements, both for end-user management and security. Note that if users have permission to run CGI scripts on the server, additional configuration will be required to ensure this is completed reliably.
Depending on whether the content is static or dynamic, this will also affect your configuration:
Use mod_vhost_alias to map individual virtual hosts in their separate directories on the server.
If you really want to, create a separate <VirtualHost> section for each known site, but then you will have to restart Apache every time a new user signs up
Use one <VirtualHost> , and then look at the host name part of the requested URL (from the $SERVER_NAME environment variable) in the scripts that display the output for displaying the contents of the user.
source share