Question

How do I set up wildcard *DOMAIN* on my droplet?

I’m working on a webapp where users can connect their profile to their domains, but how do I enable wildcard dns in digitalocean? Using vhosts or from the domain panel? Eg: If the user profile is https://webapp.com/user It will be shown on https://user.com/ once the user connects the domain.

I’m using

  1. PHP
  2. Apache
  3. Ubuntu
  4. MySQL

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.

Andy Hattemer
DigitalOcean Employee
DigitalOcean Employee badge
February 16, 2020
Accepted Answer

@Cybil Here is the approach I would take:

Update DNS to direct all subdomain requests to your Droplet

  1. Add your domain webapp.com without any subdomains to the DO Control Panel. add root domain
  2. Add an A Record entry to DNS where an asterisk * is the host name and your droplet is selected as the target so that all subdomains route Add * wildcard A-Record

Now the DNS record is directing all subdomain URL requests (user1.webapp.com, user2.webapp.com) to your Droplet. To ensure the root domain is also pointing to webapp.com, add an @ A-Record too.

Note: From our documentation:

(Use) A wildcard (*). To direct requests for a non-existent subdomain to a server or load balancer, enter *. However, if any kind of DNS record exists for a hostname, the wildcard will not apply; you will need to explicitly create an A record for it. https://www.digitalocean.com/docs/networking/dns/how-to/manage-records/#a-records

Update Apache config on Droplet to map all subdomains to the right webapp route

  1. Enable the mod_vhost_alias extension on Apache with sudo a2enmod vhost_alias and then restart Apache with systemctl restart apache2
  2. Update your Apache config to add a VirtualHost block that maps subdomains to the proper PHP route
# ROOT DOMAIN CONFIG
<VirtualHost *:80>
    ServerName webapp.com
    DocumentRoot /path/to/webapp
</VirtualHost>

#DYNAMIC SUBDOMAIN CONFIG
<VirtualHost *:80>
    ServerAlias *.webapp.com
    VirtualDocumentRoot /path/to/webapp/users/%1.php
</VirtualHost>

Lastly restart apache again with systemctl restart apache2

Hi,

Maybe you want to say https://users.webapp.com? Your question is to add subdomains for every user and enable https access?

Maybe you can turn to acme.sh and it will redirect to a GitHub repo with more information on setting up https. At there you can find what you want.

As for wildcard subdomains, just add *.webapp.com in your DNS console. That means, * is the record, and YOUR SERVER IP is the value.

Regards, Shiroka

Try DigitalOcean for free

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

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more