Configuring multiple failover IPs on a Bare Metal Cloud Server

Overview

While it is perfectly possible to host several websites on one shared IP address, there are sometimes cases where you do not want to share the IP address of a certain website with other websites on the same server. In this case you can use failover IPs to setup several IP addresses on the same server and configure Nginx to serve different content on the IPs.

In this tutorial you will learn how to configure a Bare Metal Cloud server with two failover IPs to serve two different websites.

IP failover addresses are additional IP addresses, available for Bare Metal Cloud Servers. They allow you to move an IP from one server to another without changing your whole configuration. Failover IPs can also be used as additional IP addresses to create virtual machines on your Bare Metal Cloud Server.

Note: Failover IPs are available for Bare Metal Cloud Servers and Scaleway Dedibox and offer different functionalities than reserved IPs on virtual instances.

Requirements

Configuring multiple IPs with Netplan on Ubuntu Bionic Beaver

1 . Log into your Bare Metal Cloud server using SSH.

2 . Update the apt packet cache and upgrade the software already installed on the server.

apt update && apt upgrade -y

3 . Since Ubuntu 18.04 netplan is the default tool for network configuration. Configuration are stored in [YAML](https://en.wikipedia.org/wiki/YAML- files. Open the file /etc/netplan/01-netcfg.yaml in a text editor and configure a the networking for your server.

nano /etc/netplan/01-netcfg.yaml

The IP addresses have to be written with their CIDR notation. The netmask of the principal IP of the server is /24 and /32 for each failover IP. Your configuration file should look like in the following example:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0f0:
      addresses: [51.x.y.z/24, 212.a.b.c/32, 212.d.e.f/32]
      gateway4: 51.x.y.1
      nameservers:
        addresses: [ "62.210.16.6", "62.210.16.7" ]

Important: Replace the examples above with the servers main IP as well as your failover IPs. The value for gateway4 is your servers main IP address ending on .1. For example, if your servers IP address is 51.15.15.51 the gateway IP address is 51.15.15.1.

4 . Save the file and exit the text editor.

5 . Enable the new network configuration to bring the failover IPs up:

netplan apply

6 . Check if the failover IP is working by running a ping test from your local computer:

ping 212.a.b.c

Installing and Configuring Nginx

1 . Install the Nginx web server using apt, if required you can also install additional software to setup a full LEMP environment:

apt install nginx

2 . Open a text editor and create a virtual server configuration for the first failover IP:

nano /etc/nginx/sites-available/site1

3 . Copy the server block into the newly created configuration file, and edit it towards your requirements. Then save the file and exit the text editor:

server {
       listen 212.a.b.c:80;

       server_name site1.tld;

       root /var/www/site1;
       index index.html;

       location / {
               try_files $uri $uri/ =404;
       }
}

4 . Repeat the procedure for the second virtual server configuration:

nano /etc/nginx/sites-available/site2

5 . Copy the server block into the newly created configuration file, and edit it towards your requirements. Then save the file and exit the text editor:

server {
       listen 212.d.e.f:80;

       server_name site2.tld;

       root /var/www/site2;
       index index.html;

       location / {
               try_files $uri $uri/ =404;
       }
}

6 . Create the directories for storage of both websites:

mkdir /var/www/site1 && mkdir /var/www/site2

7 . Enable the newly created sites by creating a symlink in the /etc/nginx/sites-enabled/ directory:

ln -s /etc/nginx/sites-available/site1 /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/siteé /etc/nginx/sites-enabled/

8 . Check the nginx configuration for syntax errors:

nginx -t

10 . Open a text editor and create a test site for site1:

nano /var/www/site1/index.html

Copy the following content into the file before saving it, then exit the text editor:

<html>
<head>
<title>This is site1</title>
</head>
<body>
<h1>Installation successful. This is <i>site1</i></h1>
</body>
</html>

11 . Repeat the step above for site2:

nano /var/www/site2/index.html

Copy the following content into the file before saving it, then exit the text editor:

<html>
<head>
<title>This is site2</title>
</head>
<body>
<h1>Installation successful. This is <i>site2</i></h1>
</body>
</html>

12 . Reload the Nginx web server configuration:

service nginx reload

13 . Open a web browser and point it to the IP of site1. The newly created website displays:

Site1

14 . Open another tab in your browser and point it to the IP of site2. It displays the website that has been configured for the IP address:

Site2

Discover the Cloud That Makes Sense