Question

Automatically manage subdomains (without editing vhosts) apache

Hi!

I’ve decided to give digitalocean a try. I wanted to have more control of my remote dev enviroment but I guess it was more of the need to get my hands dirty with server management.

I’ve bought domain with local hosting and would like to point subdomains with projects on my Digital Ocean VPS.

Is there a way to setup vhosts in a way that they would simply point to a specific folder that when I create a new folder it would be automaticall “mapped”? Also do I have to create the specific subdomain with my local hosting service every time i need a new one? Or if i point my domain to the droplet all new subdomains will automatically work?

What are my options here? Thanks!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You can try mod-vhost-alias.

Summary
This module creates dynamically configured virtual hosts, by allowing the IP address and/or the Host: header of the HTTP request to be used as part of the pathname to determine what files to serve. This allows for easy use of a huge number of virtual hosts with similar configurations.

You can use VH like following:

GNU nano 2.5.3 File: /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        VirtualDocumentRoot /var/www/%0/html

        <Directory /var/www/%0/html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I tested it and it worked for me. %0 means it will substitute it with full link. So if someone goes example.example.com, it’ll use it. You can also use %1, to use only first part. For more look at above link provided.

Edit, Just to note, you need to add wildcard CNAME record @ to make desired effect.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.