Question

Set up a subdomain on one droplet

Posted October 31, 2015 9.7k views
ApacheLAMP StackDNSConfiguration ManagementControl Panels

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.
    #ServerName www.example.com

    ServerAdmin corentin.branquet@gmail.com
    ServerName subdomain.domain.com
    ServerAlias www.subdomain.domain.com
    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
</VirtualHost>

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

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

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.

×
2 answers

Try doing a propagation checker on your domain to see if the DNS changes has been propagated: https://syscoding.com/network/propagation/

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):

127.0.1.1 hostname.yourdomain.ext
127.0.0.1 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 127.0.1.1 resulting in:

127.0.1.1 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).

Submit an Answer