🧩 Langkah Lengkap: Konfigurasi Apache2 as Reverse Proxy di AlmaLinux Server
🥇 1️⃣ Ubah File Root HTML Nginx
File root Nginx di AlmaLinux:
/usr/share/nginx/html/index.html
Edit dengan:
sudo nano /usr/share/nginx/html/index.html
Isi file:
<!DOCTYPE html>
<html>
<head><title>Test Reverse Proxy</title></head>
<body>
<h2>Nama Kalian</h2>
<pre>Reverse Proxy Sukses</pre>
</body>
</html>
Simpan (Ctrl + O, Enter, Ctrl + X).
🥈 2️⃣ Ubah Port Apache2 (httpd) ke Port Default 80
Buka file konfigurasi:
sudo nano /etc/httpd/conf/httpd.conf
Pastikan baris berikut ada dan tidak dikomentari (#):
Listen 80
🥉 3️⃣ Ubah Port Bawaan Nginx Menjadi 8183
Edit konfigurasi utama:
sudo nano /etc/nginx/nginx.conf
Cari baris:
listen 80;
Ubah menjadi:
listen 8183;
Pastikan tidak ada file lain di /etc/nginx/conf.d/ yang memakai port 80:
sudo grep -r "listen 80" /etc/nginx/conf.d/
Lalu cek konfigurasi Nginx:
sudo nginx -t
Jika berhasil:
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart service:
sudo systemctl restart nginx
🧱 4️⃣ Ubah Apache2 Jadi Reverse Proxy ke Nginx Port 8381
Edit lagi file Nginx:
sudo nano /etc/nginx/nginx.conf
Ubah:
listen 8183;
Menjadi:
listen 8381;
Simpan dan restart:
sudo nginx -t sudo systemctl restart nginx
⚙️ 5️⃣ Pastikan Modul Proxy Apache Aktif
Buka file modul:
sudo nano /etc/httpd/conf.modules.d/00-proxy.conf
Pastikan baris berikut tidak dikomentari:
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
🌐 6️⃣ Buat File VirtualHost Reverse Proxy Apache
Buat file baru:
sudo nano /etc/httpd/conf.d/reverse-proxy.conf
Isi dengan konfigurasi berikut:
<VirtualHost *:80>
ServerName localhost
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8381/
ProxyPassReverse / http://127.0.0.1:8381/
ErrorLog /var/log/httpd/reverse_proxy_error.log
CustomLog /var/log/httpd/reverse_proxy_access.log combined
</VirtualHost>
🔥 7️⃣ Buka Firewall
Jika firewalld aktif, jalankan:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload
🚀 8️⃣ Restart Semua Service
sudo systemctl restart nginx sudo systemctl restart httpd
Periksa status:
sudo systemctl status nginx sudo systemctl status httpd
Keduanya harus active (running).
✅ 9️⃣ Lakukan Pengetesan
Buka browser atau gunakan perintah:
curl http://127.0.0.1/
Atau dengan IP server:
curl http://<IP_AlmaLinux>/
Jika berhasil, muncul:
Nama Kalian Reverse Proxy Sukses
🎯 Artinya Apache2 berhasil sebagai Reverse Proxy ke Nginx (port 8381) tanpa error.
Komentar
Posting Komentar