Skip to main content
  1. Posts/

Menggunakan Apache Sebagai Proxy dan Load Balancer

1 min
apache apache ubuntu
Table of Contents

Load balancing adalah proses mendistribusikan lalu lintas di beberapa server untuk ketersediaan tinggi (HA) dan skalabilitas elastis.

Umumnya HAProxy sering digunakan sebagai proxy dan load balancer tetapi ada alternatif lain dengan menggunakan modul proxy dari webserver Apache Anda sehingga tidak perlu menginstall HAProxy.

Activating The Modules
#

Aktifkan beberapa modul berikut.

a2enmod proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html lbmethod_byrequests

Enabling Proxy
#

Edit atau buat file baru untuk konfigurasi proxy

nano /etc/apache2/sites-available/web.conf
<VirtualHost *:80>
        ProxyPreserveHost On
        
        # Servers to proxy the connection, or;
        # List of application servers:
        # Usage:
        # ProxyPass / http://[IP Addr.]:[port]/
        # ProxyPassReverse / http://[IP Addr.]:[port]/
        # Example: 
        ProxyPass / http://0.0.0.0:8080/
        ProxyPassReverse / http://0.0.0.0:8080/
        
        ServerName localhost
    </VirtualHost>

Enabling Load-Balancing
#

Untuk menggunakan fitur load balancing Apache

    <Proxy balancer://mycluster>
        # Server 1
        BalancerMember http://127.0.0.1:8080

        # Server 2
        BalancerMember http://127.0.0.1:8081
    </Proxy>

<VirtualHost *:80>
    ServerAdmin webmaster@yourserver.com
    ServerName yourserver.com
    ErrorLog "/var/log/apache2/web1-error_log"
    CustomLog "/var/log/apache2/web1-access_log" common
    ProxyPass / balancer://mycluster/
</VirtualHost>

Sesuaikan kembali dengan lingkungan backend atau aplikasi yang Anda jalankan.

Restarting Apache
#

Setelah dikonfigurasi Anda perlu restart service Apache perubahan dapat diterapkan di server.

systemctl restart apache2

Related

Install Apache dengan PHP-FPM dan Userdir
3 mins
apache ubuntu linux php apache
Setup Apache dan PHP-FPM di Docker
7 mins
apache docker apache php
Custom Log Format in Apache
1 min
apache apache linux
How to use mod_rewrite in Apache
2 mins
apache apache
Monitor Apache Web Server with mod_status
1 min
apache apache
Cara Menginstal ModSecurity di Apache
4 mins
apache apache modsec