Sebelum memulakan lab ini, pastikan anda sudah ada:
- ✅ EC2 instance yang berjalan dengan Nginx (dari Lab 6-8)
- ✅ Domain name sendiri yang sudah add ke Cloudflare
- ✅ Akaun Cloudflare (free tier sudah memadai)
- ✅ Public IP address dari EC2 instance anda
Dalam lab ini, anda akan belajar:
- Mencari Public IP address EC2 instance
- Login ke Cloudflare Dashboard
- Menambah A record untuk point root domain ke server AWS
- Configure Cloudflare settings untuk optimal performance
- Verify domain sudah berfungsi
-
Pergi ke AWS Console → EC2 Dashboard
-
Click pada instance anda
-
Dalam bahagian Details, cari dan copy Public IPv4 address
Contoh:
54.123.45.67
Nota: Jika instance anda restart, Public IP akan berubah! Untuk production, guna Elastic IP (IP statik).
- Pergi ke https://dash.cloudflare.com
- Login dengan email dan password anda
- Anda akan nampak list domain anda
- Click pada domain yang ingin anda configure
- Selepas pilih domain, anda akan berada di overview page
- Di sebelah kiri menu, click DNS
- Atau click tab DNS di bahagian atas
- Anda akan nampak DNS Records section
Jika ada A record atau CNAME record untuk root domain (@ atau example.com), delete dahulu:
- Cari record dengan Name =
example.comatau@ - Click butang Edit atau click pada record
- Click Delete
- Confirm deletion
-
Click butang Add record (biasanya berwarna biru)
-
Isikan maklumat berikut:
Field Value Penjelasan Type AA record untuk point ke IP address Name @Simbol @bermaksud root domainIPv4 address 54.123.45.67Public IP EC2 anda Proxy status 🔴 DNS only Pilih "DNS only" (gray cloud) TTL AutoAutomatic TTL -
PENTING: Pastikan Proxy status adalah DNS only (gray cloud icon 🔴)
- Proxied (orange cloud ☁️): Traffic melalui Cloudflare (gunakan jika mahu CDN)
- DNS only (gray cloud): Direct connection ke server anda
-
Click Save
Contoh configuration:
Type: A
Name: @
IPv4 address: 54.123.45.67
Proxy status: DNS only (gray cloud)
TTL: Auto
Penjelasan:
@= root domain (contoh:example.com, bukanwww.example.com)A record= Mapping domain ke IPv4 addressDNS only= Cloudflare hanya handle DNS, tak proxy trafficTTL Auto= Cloudflare automatically manage TTL
Untuk www.example.com juga boleh diakses:
Option 1: Guna A Record (sama macam root)
-
Click Add record
-
Isikan maklumat:
Field Value Type AName wwwIPv4 address 54.123.45.67Proxy status 🔴 DNS only TTL Auto -
Click Save
Option 2: Guna CNAME Record (lebih baik)
-
Click Add record
-
Isikan maklumat:
Field Value Type CNAMEName wwwTarget example.comProxy status 🔴 DNS only TTL Auto -
Click Save
Nota: CNAME lebih baik sebab jika IP berubah, anda hanya perlu update satu record sahaja (root domain).
Di Cloudflare DNS Records page, anda sepatutnya nampak:
Type Name Content Proxy status TTL
A example.com 54.123.45.67 DNS only Auto
CNAME www example.com DNS only Auto
Cloudflare updates DNS sangat cepat (biasanya dalam beberapa saat).
# Check A record untuk root domain
dig example.com
# Check A record untuk www
dig www.example.com
# Atau guna command ni untuk result lebih simple
dig +short example.comExpected output:
54.123.45.67
Pergi ke: https://dnschecker.org
- Masukkan domain anda:
example.com - Pilih record type:
A - Click Search
- Verify kebanyakan location show IP address anda
-
Buka browser (Chrome, Firefox, Safari)
-
Type domain anda dalam address bar:
http://example.comGanti dengan domain anda!
-
Tekan Enter
Expected result:
Welcome to nginx!
✅ Domain anda berjaya point ke AWS server!
- Test juga dengan
www:http://www.example.com
Solusi:
- Check DNS records di Cloudflare - pastikan A record betul
- Tunggu beberapa minit untuk DNS propagate
- Clear DNS cache di komputer anda:
# macOS sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder # Windows ipconfig /flushdns # Linux sudo systemd-resolve --flush-caches
Solusi:
- Pastikan Proxy status adalah DNS only (gray cloud), bukan Proxied (orange cloud)
- Jika mahu guna Proxied, kena configure Security Group untuk allow Cloudflare IPs
Solusi:
- Check EC2 instance Security Group:
- Pergi ke EC2 → Security Groups
- Pastikan ada inbound rule untuk HTTP (port 80) dari
0.0.0.0/0
- Check Nginx service running:
sudo systemctl status nginx
- Check EC2 instance masih running di AWS Console
Solusi:
- Guna Elastic IP (IP statik dari AWS):
- EC2 Dashboard → Elastic IPs
- Allocate Elastic IP address
- Associate dengan EC2 instance anda
- Update A record di Cloudflare dengan Elastic IP baru
- Guna Elastic IP: Supaya IP tidak berubah bila restart instance
- Enable Cloudflare Proxy: Untuk CDN, security, dan free SSL
- Configure SSL: Guna Cloudflare Origin Certificate di Nginx
- Enable Security Features: Firewall rules, rate limiting, bot protection
- Monitor Analytics: Check traffic pattern di Cloudflare dashboard
Cloudflare Proxy Status:
-
DNS only (gray cloud): Direct connection ke server
- Pros: Simple setup, full control
- Cons: No CDN, no extra security, real IP exposed
-
Proxied (orange cloud): Traffic melalui Cloudflare
- Pros: CDN, DDoS protection, free SSL, hide real IP
- Cons: Perlu configure security group, slightly complex
DNS Record Types:
- A Record: Maps domain ke IPv4 address
- AAAA Record: Maps domain ke IPv6 address
- CNAME Record: Maps domain ke domain lain (alias)
- MX Record: Mail server records
- TXT Record: Text records (untuk verification, SPF, DKIM)
Root Domain vs Subdomain:
- Root domain:
example.com(guna@di Cloudflare) - Subdomain:
www.example.com,blog.example.com(gunawww,blog)
🎉 Tahniah! Domain anda sudah point ke AWS server menggunakan Cloudflare dan boleh diakses dari internet!