Sharing Ilmu

Sharing for useful things

How To Configuration Multiple Webserver in one server Linux ubuntu 20.04

In this tutorial I’ll discuss about how to configuration multiple webserver in one machine. I have discuss about configurations of webserver at How To Install webserver (Apache,PHP) ubuntu server 20.04 and How To Configuration Apache2 (Custom html directory) ubuntu server 20.04 .

For configuration, it requires webserver service, create custom html directory, and dns server service.  So Before configuration install webserver service and dns server service. In this article I’ll discuss it with single domain and it subdomain.For configure multiple webserver with different domain I’ll discuss it in the next article.  For example we requires 2 webserver with primary domain is taufiknurhuda.com and subdomain portal.taufiknurhuda.com in one server.

 

Make sure ip address has been configured.

 

Update system :

root@Taufik:~# apt-get update

 

Install webserver packages :

root@Taufik:~# apt-get install apache2 php7.4 libapache2-mod-php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-gd php7.4-imap php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-zip

 

Install DNS Server packages at link How To Configure DNS Server ubuntu server 20.04 LTS. For ip address, adjust to the current server ip.

Don’t forget to configure resolv.conf and hosts :

Configure resolv.conf

root@Taufik:~# nano /etc/resolv.conf

Add configuration as the following :

GNU nano 4.8                    /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 10.0.0.2

 

Configure Host :

root@Taufik:~# nano /etc/hosts

Change host configuration as the following :

127.0.0.1 localhost
127.0.1.1 taufiknurhuda.com
10.0.0.2 taufiknurhuda.com

# 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

 

CONFIGURE DNS SERVER

root@Taufik:~# nano /etc/bind/named.conf.local

Add the configuration as the following.  see at zone 0.0.10, it’s the network for server ip 10.0.0.2 written in reverse.

//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";

zone "taufiknurhuda.com" {
     type master;
     file "/etc/bind/db.domain";
};

zone "0.0.10.in-addr.arpa" {
     type master;
     file "/etc/bind/db.ip";
};

 

Change directory to /etc/bind :

root@Taufik:~# cd /etc/bind/
root@Taufik:/etc/bind#

 

Copy  default db file configuration to new db file. db.local to db.domain and db.127 to db.ip.

root@Taufik:/etc/bind# cp db.local db.domain
root@Taufik:/etc/bind# cp db.127 db.ip
root@Taufik:/etc/bind#

 

Configure db.domain :

root@Taufik:/etc/bind# nano db.domain

Do configuration as the following :

;
; BIND data file for local loopback interface
;
$TTL     604800
@          IN           SOA          taufiknurhuda.com. root.taufiknurhuda.com. (
                                                2             ;  Serial
                                           604800             ; Refresh
                                            86400             ; Retry
                                          2419200             ; Expire
                                           604800 )           ; Negative Cache TTL
;
@          IN           NS            ns.taufiknurhuda.com.
ns         IN            A                10.0.0.2
@          IN            A                10.0.0.2
www        IN            A                10.0.0.2
portal     IN            A                10.0.0.2

 

Configure db.ip :

root@Taufik:/etc/bind# nano db.domain

Do configuration as the following. 2 is the host id that used on server ip 10.0.0.2:

;
; BIND data file for local loopback interface
;
$TTL     604800
@          IN           SOA          taufiknurhuda.com. root.taufiknurhuda.com. (
                                                1             ;  Serial
                                           604800             ; Refresh
                                            86400             ; Retry
                                          2419200             ; Expire
                                           604800 )           ; Negative Cache TTL
;
@          IN           NS           ns.taufiknurhuda.com.
2         IN           PTR           taufiknurhuda.com.
2         IN           PTR           www.taufiknurhuda.com.
2         IN           PTR           portal.taufiknurhuda.com.

 

Restart bind9 service :

root@Taufik:~# systemctl restart bind9.service

 

Test the dns configuration :

root@Taufik:/etc/bind# nslookup taufiknurhuda.com
Server: 10.0.0.2
Address: 10.0.0.2#53

Name: taufiknurhuda.com
Address: 10.0.0.2
root@Taufik:/etc/bind# nslookup portal.taufiknurhuda.com
Server: 10.0.0.2
Address: 10.0.0.2#53

Name: portal.taufiknurhuda.com
Address: 10.0.0.2
root@Taufik:/etc/bind# nslookup 10.0.0.2
2.0.0.10.in-addr.arpa name = ns.taufiknurhuda.com.
2.0.0.10.in-addr.arpa name = taufiknurhuda.com.
2.0.0.10.in-addr.arpa name = portal.taufiknurhuda.com.
2.0.0.10.in-addr.arpa name = www.taufiknurhuda.com.

Dns configuration is successfull.

 

CONFIGURE WEBSERVER

Change to sites-available directory :

root@Taufik:~# cd /etc/apache2/sites-available/
root@Taufik:/etc/apache2/sites-available#

Copy file conf :

root@Taufik:/etc/apache2/sites-available# cp 000-default.conf primarywebsite.conf
root@Taufik:/etc/apache2/sites-available# cp 000-default.conf portalwebsite.conf

Configure primarywebsite.conf :

root@Taufik:/etc/apache2/sites-available# nano primarywebsite.conf

Do the configuration like this :

<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 admin@taufiknurhuda.com
                 ServerName taufiknurhuda.com
                 ServerAlias www.taufiknurhuda.com
                 DocumentRoot /var/www/html/primaryweb

            # 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

</VirtualHost>

 

Configure portalwebsite.conf :

root@Taufik:/etc/apache2/sites-available# nano portalwebsite.conf

Do the configuration like this :

<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 admin@taufiknurhuda.com
                 ServerName portal.taufiknurhuda.com
                 ServerAlias portal.taufiknurhuda.com
                 DocumentRoot /var/www/html/portalweb

            # 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

</VirtualHost>

 

Enable the new file config and disable default file config :

root@Taufik:/etc/apache2/sites-available# a2ensite primarywebsite.conf
root@Taufik:/etc/apache2/sites-available# a2ensite portalwebsite.conf
root@Taufik:/etc/apache2/sites-available# a2dissite 000-default.conf

Restart apache2 service :

root@Taufik:~# systemctl restart apache2

 

Change Directory to /var/www/html :

root@Taufik:~# cd /var/www/html/
root@Taufik:/var/www/html#

 

Create the example html directories for primaryweb and portalweb:

root@Taufik:/var/www/html# mkdir primaryweb
root@Taufik:/var/www/html# mkdir portalweb
root@Taufik:/var/www/html# ls
index.html      info.php.       portalweb       primaryweb 
root@Taufik:/var/www/html#

Create the example html file in each directories :

root@Taufik:/var/www/html# echo "THIS IS PRIMARY WEBSITE" > primaryweb/index.html

root@Taufik:/var/www/html# echo "THIS IS PORTAL WEBSITE" > portalweb/index.html

 

Do local test the webserver with domain using curl. if curl is not installed, install it using apt-get install curl

Pay attention to the following :

root@Taufik:~# curl taufiknurhuda.com
THIS IS PRIMARY WEBSITE
root@Taufik:~# curl www.taufiknurhuda.com
THIS IS PRIMARY WEBSITE
root@Taufik:~# curl portal.taufiknurhuda.com
THIS IS PORTAL WEBSITE
root@Taufik:~#

When domain is called, it will go to the html directory that appropriate on apache file conf.

Now test again through pc client.

Configure network, for ip dns is point to your server ip or dns server ip.

Open the CMD on your client and do nslookup test. make sure nslookup test is successfull.

Now test access webserver from your browser.

 

Configuration is successfull.

z

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>