Cara membuat virtual host/web server on ubuntu
Nginx is an open source high performance Load balancer and web server software. It supports HTTP, HTTPS, SMTP, POP3, and IMAP protocols as a reverse proxy server. Creating virtual host in NGINX is explained in this article.
Jika lain waktu kita sudah mengenal tutorial cara menginstall nginx , maka di tutorial ini masih kelanjutan dari aplikasi nginx server. Yaitu cara membuat virtual host lebih dari satu. Nginx sendiri merupakan aplikasi open source untuk performa tinggi dalam oad balancer dan webserver. Dan juga aplikasi ini kompatible untuk HTTP,HTTPS,SMTP,POP3 dan IMAP protokol sebagai reverse proxy server.
Kali ini saya akan membuat virtual host dengan domain
-testing1.com
-testing2.com
Oke untuk lebih jelasnya tentang bagaimana membuat virtual host langsung kita lihat saja dibawah ini.
Menginstall Nginx
Install nginx dari epel repository dengan perintah berikut
[root@linuxhelp~]# yum install --enablerepo=epel nginx
Loaded plugins: aliases, changelog, fastestmirror, kabi, security
Setting Up install process
Resolving dependencies
--> Running transaction check
--> Package nginx.x86_64 1.0.15-12.el6 will be installed.
.
.
.
Installaed:
nginx.x86_64 1.0.15-12.el6 is installed
Complete!
Start the nginx service.
[root@linuxhelp~]# service httpd stop
Stopping httpd: [ ok ]
[root@linuxhelp~]# service nginx start
Starting nginx: [ ok ]
Menentukan nama dari virtual host
Membuat user untuk mengijinkan mengakses nginx
[root@linuxhelp~]# useradd user1
Kemudian membuat folder untuk virtual domain di /var/www path.
[root@linuxhelp~]# mkdir /var/www/testing1.com/public_html
[root@linuxhelp~]# mkdir /var/www/testing2.com/public_html
Kemudian pindah ke folder public_html dan buat index.html. Lakukan juga di index.html yang testing2.com[root@linuxhelp~]# cd /var/www/testing1.com/public_html
[root@linuxhelp public_html]# vim index.html
<html>
<head>
<title>
TESTING 1
</title>
</head>
<body>
This is the first domain
</body>
</html>
Jika di folder nginx belum ada sites-available, bisa menambahkan folder sendiri dengan perintah berikut.
[root@linuxhelp~]# mkdir /etc/nginx/sites-available
Pindah ke folder tersebbut dan buatlah file configurasi untuk masing - masing virtual domain. Untuk mempermudah saja kita membuat testing1.com.conf dan testing2.com.conf.
[root@linuxhelp~]# cd /etc/nginx/sites-available
[root@linuxhelp sites-available]# touch testing1.com.conf testing2.com.conf
Tambah konfigurasi dibawah ini. Jika nama domain yang kalian buat berbeda tinggal sesuaikan nama doainnya saja.
testing1.com.conf
server{
listen 80;
server_name testing1.com www.testing1.com;
location /{
root /var/www/testing1.com/public_html;
index index.html;
}
}
testing2.com.conf
server{
listen 80;
server_name testing2.com www.testing2.com;
location /{
root /var/www/testing2.com/public_html;
index index.html;
}
}
Sekarang ubah owhnership ke user1 dan permissions ke 755 untuk semua konfigurasi dan file index.
[root@linuxhelp sites-available]# chgrp user1 *
[root@linuxhelp sites-available]# ls -l
total 8
-rw-r--r-- 1 root user1 147 Jun 27 22:27 testing1.com.conf
-rw-r--r-- 1 root user1 147 Jun 27 22:28 testing2.com.conf
[root@linuxhelp~]# cd /var/www/testing1.com/public_html
[root@linuxhelp public_html]# chgrp user1 index.html
Ikuti perintah diaatas untuk domain(www.testing2.com) .
Kemudian edit file nginx.conf dan berikan tanda pagar pada user nginx, kemudian ubah dan tambah "include" di letak folder file konfigurasi yang sudah diabuat.
#user nginx;
worker_processess 1;
http{
include /etc/nginx/mime.types;
include /etc/nginx/sites-available/*.conf;
default_type application/octet-stream;
.
.
.
}
contoh file konfigurasinya adalh berikut

Setelah konfigurasi di sisi nginx selesai , kemudian edit di file /etc/hosts ,agar nama domain yang kita buat bsa terdeteksi sebagai diri sendiri. Ipnya sesuakan dengan ip kalian.
[root@linuxhelp~]# vim /etc/hosts
192.168.11.182 testing1.com www.testing1.com
192.168.11.182 testing2.com www.testing2.com
Restart nginx
[root@linuxhelp~]# service nginx restart
Stopping nginx: [ ok ]
Starting nginx: [ ok ]
Langkah terakhir dengan mentest virtual domain yang sudah dibuat dengan memasukkan nama domainpada browser , http://testing1.com or http://www.testing1.com, Jika berhasil maka file yang sudah dibuat tadi akan muncul.
Virtual domain selanjutnya http://testing2.com or http://www.testing2.com

Oke teman - teman, mungkin sekian tutorial cara membuat virtuaal domain,
selamat mencoa dan semoa membantu. :)
Komentar
Posting Komentar