Cara Setting Virtual Host Apache CentOS

By | 27th April 2016

Satu VPS untuk lebih dari satu atau banyak website. Tutorial ini untuk apache dengan sistem operasi linux CentOS, Tutorial Cara Setting Virtual Host Apache CentOS agar bisa menampung multi website atau domain dalam satu VPS atau satu IP dedicated server.

Add Domain di VPS

Langsung add domain VPS melalui konfigurasi /etc/resolv.conf

vi /etc/resolv.conf

Tambahkan domain anda pada baris paling atas atau paling bawah pada file resolv.conf tersebut seperti contoh berikut ini:

search demmy.id test.demmy.id

Buka file /etc/hosts

vi /etc/hosts

Tambahkan domain anda contoh:

127.0.0.1 localhost.localdomain localhost demmy.id test.demmy.id
::1 localhost.localhostdomain localhost demmy.id test.demmy.id

Konfigurasi httpd Apache

Pada CentOS konfigurasi apache terletak di /etc/httpd/conf

vi /etc/httpd/conf/httpd.conf

edit baris ini dan hilangkan pagar

NameVirtualHost Ipserveranda:80

dan tambahkan di paling bawah , saya merubah DocumentRoot ke  /home/httpd/

 

<VirtualHost 192.168.148.120:80>
    ServerAdmin dnadnaxx@xxxxx.com
    DocumentRoot /home/httpd/demmyid/
    ServerName demmy.id
    ErrorLog /home/httpd/demmyid/error.log
    CustomLog /home/httpd/demmyid/request.log combined
</VirtualHost>

<VirtualHost 192.168.148.120:80>
    ServerAdmin dnadnaxx@xxxx.com
    DocumentRoot /home/httpd/testdemmy/
    ServerName test.demmy.id
    ErrorLog /home/httpd/testdemmy/error.log
    CustomLog /home/httpd/testdemmy/request.log combined
</VirtualHost>

Keterangan:
ServerAdmin dnadnaxx@xxxx.com :
Alamat email anda duntuk demmy.id

DocumentRoot /home/httpd/demmyid :
Letak file-file website khusus untuk domain demmy.id

ServerName demmy.id:
Nama domain

ErrorLog /home/httpd/demmyid/error.log :
custom error log, misal jika sciprt error, file error karena tidak ditemukan nanti log nya terekam di error.log

CustomLog /home/httpd/demmyid/request.log combined :
Custom log untuk record user yang mengakses domain demmy.id

Anda juga bisa menambahkan domain yang lain dengan cara menambahkan kode seperti diatas pada file konfigurasi /etc/httpd/conf/httpd.conf.

Restart Apache

service httpd restart

silahkan untuk di coba akses