Currently I have a droplet ‘mydomain.com’ which works accessed via www.mydomain.com and mydomain.com.
I also have ‘example.mydomain.com’ setup which only works when accessed via example.mydomain.com, but not www.example.mydomain.com.
Am i able to set it up so a user can type ‘www’ before ‘example.mydomain.com’?
Thanks
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!
@eKulz - You really don’t need the CNAME entry. You can use a WildCard DNS entry to handle all sub-domain routing, which will prevent you from having to handle multiple DNS entries over time and allow you to do the configuring at the web server level.
Adding an A entry using an asterisk ( i.e. * ) and setting the hostname to your Droplet IP will route all requests for sub.domain.ext to domain.ext unless the sub-domain is defined in your web server configuration or a directory with that name exists.
As an example, I’ll use NGINX. NGINX will require that you setup your server block to use the WildCard Entry by defining it. As you can see below, normally you’d use www.mydomain.com, though to ensure proper routing, we use an asterisk - save & reload NGINX.
server {
listen 80;
server_name mydomain.com *.mydomain.com;
...
......
}
Now, if we go to sub.mydomain.com, we’ll see the content of mydomain.com. If we wanted to ensure sub.mydomain.com displayed its own content, we’d simply setup a server block for it.
server {
listen 80;
server_name sub.mydomain.com www.sub.mydomain.com;
...
......
}
Since we have a WildCard DNS entry in place, we don’t need to create another DNS entry, regardless of how many additional sub.mydomain.com server blocks we create (i.e. sub2.mydomain.com, sub3.mydomain.com etc).
Question can be removed, I managed to get it working
I added a CNAME record name: ‘www.example.mydomain.com’ hostname: ‘example.mydomain.com’
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.