Setting Subdomain di Vultr menggunakan Cloudflare

Hanya sebuah dokumentasi pribadi

Yeah, akhirnya berhasil menyewa VPS di Vultr. Karena di rekomendasi oleh seorang teman saya, sebenarnya saya lebih enjoy menggunakan DigitalOcean. Selain Interface nya simple dan mudah digunakan, DigitalOcean juga telah banyak dipercayai oleh perusahaan besar.

But, dengan harga $5 per-bulan, DigitalOcean memberikan 20 GB SSD Disk, sedangkan Vultr hanya 15GB. Untuk transfer bandwith pun seimbang, 1TB. Tapi, Vultr memberikan RAM 768 MB. yang mana digitalocean hanya 512 MB. Bukan perbandingan yang penting, ya?

Next, lalu bagaimana cara setting Subdomain nya? Sebelumnya, berikut Technology Stack yang akan kita pakai:

  • Web Server: Apache2
  • CDN: Cloudfare
  • VPS: Vultr

Let’s go

Daftar Cloudflare dan tambahkan situs

Ya, buka Cloudflare. Klik + Add Site, tulis domain kamu, dan tunggu si Cloudflare selesai melakukan tugas nya. Kalo udah selesai, biasanya kita disuruh ganti Nameserver default kita (kalo baru beli), atau Nameserver sebelumnya, ke Cloudflare.

Point Nameserver utama kamu ke Cloudflare

Login ke Control Panel tempat kamu beli domain, lalu di Name Server, silahkan pointing ke Cloudflare. Biasanya, untuk yang Free Plan, nameserver nya kesini:

  • janet.ns.cloudflare.com
  • norman.ns.cloudflare.com

Tambahkan “A” di Cloudflare anda

Jika sudah klik Add Record.

Setting konfigurasi apache

# buka /etc/apache2/sites-available
username@hostname ~ $ cd /etc/apache2/sites-available
# copy 000-default.conf dengan nama subdomain.conf. Menggunakan perintah sudo ya
username@hostname /etc/apache2/sites-available $ sudo cp 000-default.conf subdomain.conf
# buka file tersebut, lalu edit
username@hostname /etc/apache2/sites-available $ vi subdomain.conf

Beginilah kira-kira isi file subdomain.conf, lalu ganti yang di bold.

<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 webmaster@localhost
DocumentRoot /var/www/html
# 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>

Kira-kira menjadi seperti ini (misal nama subdomain nya blog):

<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 blog.domain.com
ServerAdmin terserah@emailkamu.com
# kita taro di direktori /var/www/blog
DocumentRoot /var/www/blog
# 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>

Lalu save dengan perintah — ESC. Lalu :wq — setelah selesai jalankan perintah sudo a2ensite subdomain.conf untuk meng-enable situs dari konfigurasi tersebut, dan sudo service apache2 reload untuk me-reload apache2.

Biasanya butuh waktu untuk bisa meng-aktifkan http://blog.domain.com/ kalo pas di buka URL nya masih The Site Can’t be reached, tunggu aja.

Selesai deh. Kalo pengen nambahin subdomain lagi, tinggal tambahin “A” di Cloudflare, buat copy file yang ada di sites-available/*.conf, buat direktori di /var/www/** atau dimanapun terserah, lalu lakukan perintah a2ensite, selesai!

Kenapa pake Cloudflare (GRATIS!)?

  • SSL Gratis, Hahaha! Wildcard lagi
  • Dapet 3 Page rules, jadi misalnya auto redirect kalo user akses ke non-ssl, bisa default redirect ke SSL/HTTPS.
  • CDN! Hemat bandwith, and page load faster than non-using CDN

Kenapa Vultr?

  • Nyoba-nyoba, siapa tau aja jodoh
  • Alternatif dari DigitalOcean.
  • Dapet credit gratis sebesar $20, setelah menghubungkan kartu kredit atau Paypal. Klik dong link referal gue disini

Semoga bermanfaat, terima kasih!

Disclaimer:

Tulisan disini mengandung link referal