أداة HAProxy: شرح وتثبيت

عندما نتحدث عن "توزيع الأحمال" (Load Balancing) عالي الأداء، فإن الاسم الأول الذي يتبادر للذهن هو HAProxy. يستخدمه عمالقة مثل Twitter و GitHub و Stack Overflow لمعالجة ملايين الطلبات في الثانية.

ما هو HAProxy؟

هو برنامج مفتوح المصدر يوفر موازنة أحمال (Load Balancer) وبروكسي عكسي (Reverse Proxy) لتطبيقات TCP و HTTP. يتميز بالسرعة الخارقة واستهلاك الموارد المنخفض جداً.

المفاهيم الأساسية

  • Frontend: يستقبل الطلبات من العملاء (يحدد البورت والبروتوكول).
  • Backend: مجموعة السيرفرات التي يتم توجيه الطلبات إليها.
  • ACLs: قواعد مرنة جداً لتوجيه الحركة (مثلاً: توجيه طلبات /api إلى سيرفرات مختلفة عن /static).

مثال تكوين بسيط (haproxy.cfg)


frontend http_front
    bind *:80
    acl url_api path_beg /api
    use_backend api_servers if url_api
    default_backend web_servers

backend web_servers
    balance roundrobin
    server web1 10.0.0.1:80 check
    server web2 10.0.0.2:80 check

backend api_servers
    server api1 10.0.0.3:8080 check
                    

HAProxy vs Nginx

بينما Nginx هو ويب سيرفر شامل يمكنه عمل Load Balancing، فإن HAProxy متخصص فقط في الـ Proxying. هذا يجعله يتفوق في الخوارزميات المعقدة لتوزيع الأحمال والمراقبة الدقيقة لحالة السيرفرات (Health Checks).

Disclosure: we may earn a commission if you purchase through some links.

Services Related To This Article

These offers are related to privacy, password security, and development workflows. Replace the current links with your real affiliate links through environment variables.

Default Links Need Replacement

Proton

Privacy, mail, and VPN

A strong fit for privacy-focused visitors who want VPN and secure email under one brand.

Explore Proton

Surfshark

Consumer VPN

Best on pages about geo-blocking, privacy, and public Wi-Fi protection.

Try Surfshark

NordVPN

High-converting VPN

A clear offer for users who need a paid, more durable alternative to a free proxy.

View NordVPN

1Password

Password management

The best match for password, secrets, team access, and personal security pages.

Discover 1Password

DigitalOcean

Developer cloud hosting

A strong fit for proxy setup, server, and infrastructure content aimed at developers and small teams.

Start with DigitalOcean