Set up a subdomain on one droplet

October 31, 2015 9.4k views
DNS Control Panels Apache LAMP Stack Configuration Management

Hi everyone !

I want to create a subdomain on my droplet.

I Set my Records like this
A: @ / 104.155.xx.xx
A: subdomain / 104.155.xx.xx (same Ip)

Then I create a vhost on Apache for my subdomain : subdomain.conf

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    DocumentRoot /var/www/subdomain/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I enabled this subdomain, restart Apache, but when try in my brower, it does not work.

2 Answers

Try doing a propagation checker on your domain to see if the DNS changes has been propagated:

Also try clearing your DNS cache.

@corentinbranque - You may want to take a look at /etc/hosts and add an entry for your sub-domain. In some cases, this may be required.

You should see something like this (this was pulled from a fresh Droplet just now): hostname.yourdomain.ext localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

You would simply add subdomain.yourdomain.ext (where ext = your domain extension - .com, .net etc) and perhaps www.subdomain.yourdomain.etc to the existing line for resulting in: hostname.yourdomain.etc subdomain.yourdomain.etc www.subdomain.yourdomain.ext

At that point, save and exit - flush your browser cache / local cache (on your PC/Mac) and if you happen to use an ISP that heavily caches requests, you may need to reset your modem (I’ve had to do this more than I care to with my ISP) to refresh the signal (this seems to be the only way to get Charter Communications to signal a flush where I am - Comcast is similar, though I can’t speak for others).

Have another answer? Share your knowledge.