Sharing Ilmu

Sharing for useful things

Configure Multiple webserver in Single IP with HaProxy (linux ubuntu) and Mikrotik

Hello everyone, In this tutorial I’ll discuss about configuration multiple webserver in single ip.  when you have more than one webserver  and you want both webserver can be access from network in public area you can solved those problem with haproxy and mikrotik.

In the following are topologi used for this tutorial.  For this lab practice im using VirtualLab EVE-NG. if you have GNS3 you can use it too.

First do configure basic for router R-Server and R-DNS so that the router can be connected internet and R-Server can distribute internet connection for those local client.

Configure Local IP for R-Server


Configure Network for linux server that used for Haproxy and server for Web1 and Web2. Make sure whole server can connected to internet.

Configure ip address for Haproxy server in /etc/network/interfaces

# nano /etc/network/interfaces

Configure ip dns in /etc/resolvconf/resolv.conf.d/base

# nano /etc/resolvconf/resolv.conf.d/base


Configure ip address for Web server1 Web server2 in /etc/network/interfaces

Webserver1 :

Webserver2 :

resolvconf for Webserver1 and Webserver2 :


After doing the configuration reboot for Haproxy server, webserver1 and webserver2 for reload dns configuration on those server. make sure the server can connected to internet.

Install apache2 package on webserver1 and webserver2.:

# apt-get install apache2

Edit index html for webserver1 :

# echo “This is WEBSITE 1” > /var/www/html/index.html

Edit index html for webserver2 :

# echo “This is WEBSITE 2 ” > /var/www/html/index.html

Test webserver on webserver1 and 2


Install haproxy package on Haproxy server

# apt-get install haproxy

Configure haproxy script in /etc/haproxy/haproxy.cfg

# nano /etc/haproxy/haproxy.cfg

add frontend script and backend script as the following image.

Restart and check status haproxy . make sure the configuration haproxy not appears error messages.

Add dstnat configuration in ip firewall nat on  R-Server for redirect incoming traffic to R-Server is going to Local IP Haproxy server.

For Testing haproxy function. First configure R-DNS for DNS resolver. in this example I have create 2 domain that and and point those domain to ip address (ip R-server).


Configure DNS for client manually so that client can be access domain for server1 and server2


Test connection to webserver


Test Access to website


Configuration was succesfull.

Leave a Reply

Your email address will not be published. Required fields are marked *.

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>