Question

Set primary domain for droplet IP address

Posted April 27, 2017 2.3k views
Server OptimizationUbuntu 16.04

I have several domains on one droplet (a few simple static websites).

When I access the droplet IP address from a browser, one of those sites (let’s call it example.com) shows up.

How can I change which site appears as the default for the IP address?

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.

×
3 answers

@recursional

It depends on your web server.

Apache uses the first VirtualHost configuration it finds, after sorting numerically then alphabetically.

For example, if you have three VirtualHost configurations:

adomain.com.conf
mydomain.com.conf
randomdomain.com.conf

Apache will use adomain.com.conf as the default go-to when a request could not be otherwise sent to an actual domain on the server.

If, for example, you had a more mixed naming system such as:

000-domain.com.conf
adomain.com.conf
mydomain.com.conf
randomdomain.com.conf

Instead of adomain.com.conf, Apache will use 000-domain.com.conf since it’s numbered.

NGINX uses a far better, user-configurable method. Add default_server to one (and only one) of your server blocks and it’s now the default.

For example (covering both IPv4 and IPv6):

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /path/to/home;

    location / {
        ...
        ...
        ...
    }
}

So to fix this on Apache or NGINX, you’d simply create a new VirtualHost or Server Block and make sure it’s numbered on Apache, or that it has default_server defined for NGINX.

Thanks for the response. That makes sense because the first domain that I added to the droplet is the one that appears, and the droplet is running Apache (on Ubuntu).

I can’t find the location of the *.com.conf files to make changes though. Where would *.com.conf be located on Ubuntu? The files in /etc/apache2/ don’t seem to have any info specific to my domains.

I should mention that I set up the domains via ServerPilot as separate “apps”

Anyone else know the answer?

Submit an Answer