In for example, CPanel, I can easily redirect a subdomain to a folder so that it looks like two different sites.
On my DigitalOcean control panel, I can set a DNS A record to point a subdomain at an IP address, but I can’t figure out how to make it go to a specific folder. My motivation is so I can put a ‘fun and crazy’ website seperate from my ‘professional work’ website.
I have looked at using .htaccess, but Apache recommends editing the httpd.conf file as I have access to that (I am on Fedora). I can make a redirect from subsite.site.com to site.com/subsite, however I would really like subsite.site.com to show different content to subsite2.site.com and also different to site.com.
I can see some indication in Digital Ocean Apps that I can configure up to 3 sites this way for ‘free’, but I do not know which app to deploy or how to do it there.
I am on a DO Droplet running Fedora and Apache.
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!
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.
Hey Matt! 👋
To achieve what you’re aiming for, where each subdomain (like
sub1.site.com
andsub2.site.com
) points to a separate directory on your server, you’ll want to use Apache Virtual Hosts. This allows you to configure Apache to serve different content based on the subdomain.You can check out the guide here:
But overall the process is similar on Fedora.
Here’s a quick guide to setting this up:
In your DigitalOcean control panel, make sure you’ve set up A records for each subdomain (
sub1.site.com
,sub2.site.com
, etc.) that point to your Droplet’s IP address. It sounds like you’ve already done this step!On your Droplet, create separate directories to hold the files for each subdomain. For example:
Place your website files in each respective directory.
Open Apache’s configuration file for virtual hosts. On Fedora, you may need to edit the file located at
/etc/httpd/conf/httpd.conf
, or, if Virtual Hosts are in a separate directory, look under/etc/httpd/conf.d/
.Add separate
<VirtualHost>
blocks for each subdomain. Here’s an example configuration:This tells Apache to serve files from
/var/www/sub1
when someone visitssub1.site.com
, and files from/var/www/sub2
forsub2.site.com
.Save the configuration file and then test it for syntax errors:
If everything looks good, restart Apache to apply the changes:
If you want to secure these subdomains with HTTPS, you can use Let’s Encrypt to generate SSL certificates for each subdomain. Certbot can automate this for Apache. Just run:
This will configure SSL for your subdomains, making them accessible via HTTPS.
Now, visit
http://sub1.site.com
andhttp://sub2.site.com
. Each subdomain should load content from its respective directory.On another note, if you’re interested in using DigitalOcean’s App Platform instead of managing this setup manually, you could deploy separate apps for each subdomain using their individual Git repositories. App Platform allows you to map custom domains (or subdomains) to different apps, and it automatically handles SSL for you.
You can check out DigitalOcean App Platform and see if that’s a better fit for your project if you’d prefer a managed setup.
Let me know how it goes or if you have more questions!
- Bobby
heya,
To serve different content for each subdomain (e.g.,
sub1.site.com
andsub2.site.com
) on your Fedora-based DigitalOcean Droplet running Apache, you can set up virtual hosts in Apache’s configuration. Here’s how:Set up DNS:
A
records for each subdomain (sub1
andsub2
), pointing them to your Droplet’s IP address. This step directs traffic for these subdomains to your server.Configure Apache:
/etc/httpd/conf.d/
on Fedora). You’ll create separate configuration files or add virtual host blocks for each subdomain inhttpd.conf
.Create Virtual Host Blocks:
<VirtualHost>
entry. This directs traffic for each subdomain to a specific directory on your server. Here’s an example setup:Create the Directories:
/var/www/sub1
and/var/www/sub2
in this example) exist and contain the content for each subdomain.Enable and Restart Apache: