Forum archive
subdomain on appliance
hello, id like to know how to add a subdomain on a concrete5 or silverstripe cms,
the situation is this:
I have a static public ip that is working with my cms (mywebsite.com), however i also like to install a little application on the same server but with a subdomain (subdomain.mywebsite.com), however i dont find the tools on the webmin adminstation page to achieve this. would you please guide me .thanks

For sure! That's easy! :)
Having said that there are lots of options on exactly how it behaves. What I'll try to provide is a fairly basic but functional setup that should broadly provide what you've asked for. If you need more advice or have specific requirements, please feel free to ask.
So what you are trying to achieve is called Name-based Virtual Hosting. The Apache docs are pretty good IMO, but I'll spell it out for you.
I'll assume that you want just basic Apache config to serve static HTML. If you have broader requirements, this will almost certainly require tweaks. This assumes that your new site will be subdomain.mywebsite.com and hosted from /var/www/subdomain, so you'll need to adjust that to your specifics.
Firstly, let's create the directory and a simple html test index file.
mkdir -p /var/www/subdomain cat > /var/www/subdomain/index.html <<EOF <!doctype html> <html> <head> <title>Test subdomain Title</title> </head> <body> <p>If you are reading this when browsing to your new subdomain, then the subdomain is working as intended. Yay! :)<p> </body> </html> EOFWe'll also ensure that the webserver has access to it. FWIW I'm just granting full ownership to the webserver:
Now, we'll create a new fairly basic virtual host site config file. My example below supports HSTS and includes a redirect from http to https:
cat > /etc/apache2/sites-available/subdomain.conf <<EOF <VirtualHost *:80> ServerName subdomain.mywebsite.com UseCanonicalName On RewriteEngine On RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] </VirtualHost> <VirtualHost *:443> ServerName subdomain.mywebsite.com SSLEngine on ServerAdmin webmaster@localhost DocumentRoot /var/www/subdomain/ <IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains" </IfModule> </VirtualHost> <Directory /var/www/subdomain/> Options +FollowSymLinks AllowOverride All Require all granted </Directory> EOFNow we'll enable the new site and restart Apache:
If you haven't already set up DNS for your subdomain you will need to set up a CNAME record (or an A record if you rather) to point to your server. FYI generally you would only have one A record per server, then additional subdomains would be CNAME records - however if you plan to move this to a different server, then an A record might be better). If you've only just done that, you'll need to wait for the change to propagate. How long that takes will depend on your DNS registrar, the TTL (Time To Live) that any existing records have and whether or not your local DNS provider honours TTLs. Best case scenario it will be instant, worst case it shouldn't take any more than 48 hours.
If you wish to test your new subdomain before DNS has propagated, you can test by adding an entry to your Desktop's hosts file (how that is done will depend on your OS).
E.g. here's the host entries I added to test this (my test server has an IP of 192.168.1.114):
Strictly speaking it shouldn't be necessary, but I generally recommend adding any domains/subdomains to the server's 127.0.0.1 (localhost) entry in it's hosts file. That way if/when the server resolves it's own domain/subdomain it will be much faster (it can skip an external DNS lookup). Here's the first line of my test server's hosts (/etc/hosts) file:
Hopefully that get's you going. If you have any issues, please post back.