Jumat, 28 Agustus 2015

Konfigurasi Virtual Host ( Subdomain )


Selain domain utama semisal tataufik.com, masih bisa kita tambahkan lagi Sub-Domain dari domain utama tersebut. Sehingga kita lebih menghemat Ip Address dan juga domain. Contoh subdomain adalah, mail.yahoo.com dan mail.google.com. Kata mail pada domain tersebutlah yang dinamakan “sub” domain.

Jika pada saat mengkonfigurasi dns anda mengikuti tutorial saya ( Konfigurasi dns server di debian 8 menggunakan bind9 ) maka anda menemukan beberapa sub-domain yaitu ftp.tataufik.com , mail.tataufik.com , portal.tataufik.com inilah sub domain yang anda buat akan tetapi jika anda membuka sub-domain tersebut maka yang keluar adalah sama lalu bagaimana anda dapat mengisi atau menganti dari setiap sub-domain anda cukup membuat virtualhost saja lalu anda aktifkan melalui apache atau anda dapat mengarahkanya ke server lain.


1. Masuk ke bind
cd /etc/bind
Edit db.forward
 - db.forward milik saya bernama db.ariyanto jadi ketiklah perintah
nano db.ariyanto
2. Lalu Tambahkan baris berikut ke bagian bawah ( sesuikan )
sub     IN      A       192.168.24.4.
3. Edit db.revese
- db.revese milik saya bernama db.07 jadi saya masukan perintah

# nano /etc/bind/db.07
4. Lalu Tambahkan baris berikut ke bagian bawah ( sesuikan)
  4       IN      PTR     sub.andijr.net
5. Buat Isi Konten Subdomain
- Buat sebuah folder dan file index untuk isi konten sub domain seperti portal

mkdir /var/www/html/subdomain


6.Lalu edit index.html
nano /var/www/html/subdomain/index.html

 Saya tambahkan script berikut

<html>
<head>
<title>
Subdomain
</title>
</head>
<body>
<marquee>SUBDOMAIN </marquee><h1> ANDI ARIYANTO</h1>
</body>
</html>


- Save

 7. Konfigurasi Virtualhost
- Pindah directory

# cd /etc/apache2/sites-available/

- Masukan perintah

#  cp 000-default.conf subdomain.conf

 Lalu edit file subdomain.conf

#  nano subdomain.conf

8. Ganti dan tambahkan beberapa baris konfigurasi seperi dibawah ini

<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@tataufik.com
        ServerName andi.net
        ServerAlias sub.andijr.net

         DocumentRoot /var/www/html/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>

pada gambar diatas diganti menjadi gambar dibawah ini

Keterangan :

  • ServerName = Nama domain
  • ServerAlias = Nama subdomain yang ingin dialihkan/dijadikan virtual alias.
  • ServerAdmin = Alamat email pemilik domain.
  • DocumentRoot = Tempat pengalihan direktori dari Virtual Alias yang dibuat.
9. Lalu aktifkan perintah untuk mengaktifkan site tersebut
a2ensite  subdomain.conf 

- Kemudian restart apache2

# /etc/init.d/apache2 restart
10.atur DNS static di mikrotik

11. Testing
- Buka browser
- Masukan url tadi ke kolom. entrt.
- Jika berhasil maka akan muncul seperti berikut

Tidak ada komentar:

Posting Komentar