Load Balancing 1C-Bitrix: HAProxy, nginx, Cases

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Showing 1 of 1All 1626 services
Load Balancing 1C-Bitrix: HAProxy, nginx, Cases
Simple
~1 day
Frequently Asked Questions

Our competencies:

Development stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1368
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    956
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    699
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    843
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    737
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    1086

Two Bitrix Servers Without a Load Balancer

Five Bitrix servers are running, but the site slows down during peaks — one server handles 80% of requests while the rest sit idle. Without a single front-end, load distribution is uneven, and a single server failure takes down the entire site. We configure load balancing turnkey: selecting the algorithm, configuring health checks, integrating with the push server and the admin panel. The result is stable operation under peak loads and infrastructure cost savings of up to 30%.

For example, for an online store with a catalog of 500,000 products, we configured HAProxy — response time dropped by 40%, and the number of lost orders fell to zero. For a news portal with 10,000 concurrent users, we used nginx upstream and tripled throughput.

Why Load Balancing Is Critical for Bitrix

Without load balancing, one server gets overloaded while another sits idle. During peaks (sales, promotions), this causes timeouts and lost orders. A load balancer evenly distributes requests, increases throughput by 2–3 times, and ensures fault tolerance: if one node fails, the rest continue working. Additionally, balancing reduces database load by caching on each node.

Which Load Balancer to Choose: HAProxy or nginx?

HAProxy is a specialized L4/L7 load balancer. It handles up to 100,000 requests per second — twice as many as nginx upstream. HAProxy provides detailed statistics (statuses, queues) and custom HTTP checks. nginx upstream is part of the web server, simpler in configuration but less flexible. According to official HAProxy documentation, for clusters of 3 or more nodes, HAProxy is recommended. For 2–3 servers and simple tasks, nginx is sufficient.

Parameter HAProxy nginx upstream
Performance up to 100k req/s up to 50k req/s
Health checks HTTP, TCP, script only HTTP
Statistics detailed (statuses, queues) basic (up/down)
Configuration complexity medium low

Comparison of Load Balancing Algorithms for Bitrix

Algorithm Description Bitrix-specific Considerations
roundrobin Requests round-robin Evenly distributes requests of varying duration — best choice
leastconn To server with fewest connections Poor for varying execution times: one node may become loaded with a heavy import
first To first available server Used for dedicated backends (push, admin)

HAProxy Configuration for Bitrix

# /etc/haproxy/haproxy.cfg

global
    maxconn 50000
    log /dev/log local0
    tune.ssl.default-dh-param 2048

defaults
    mode http
    timeout connect 5s
    timeout client 60s
    timeout server 60s
    option http-server-close
    option forwardfor
    log global

# Frontend: accept HTTPS
frontend bitrix_https
    bind *:443 ssl crt /etc/ssl/site.pem
    http-request set-header X-Forwarded-Proto https
    http-request set-header X-Real-IP %[src]

    # Admin section — dedicated backend
    acl is_admin path_beg /bitrix/admin
    use_backend bitrix_admin if is_admin

    # Push server — separate backend with long connections
    acl is_push path_beg /bitrix/pub
    use_backend bitrix_push if is_push

    default_backend bitrix_web

# Main backend — web nodes
backend bitrix_web
    balance leastconn
    option httpchk GET /bitrix/admin/cluster_check.php
    http-check expect status 200

    server web-01 10.0.0.11:80 check inter 5s rise 2 fall 3 weight 100
    server web-02 10.0.0.12:80 check inter 5s rise 2 fall 3 weight 100
    server web-03 10.0.0.13:80 check inter 5s rise 2 fall 3 weight 100

# Admin panel — only master node
backend bitrix_admin
    server web-01 10.0.0.11:80 check

# Push server
backend bitrix_push
    timeout server 3600s
    server push-01 10.0.0.14:8893 check

balance roundrobin — requests are sent round-robin. For Bitrix with varying response times, this is preferable to leastconn. Parameters rise 2 fall 3 — a node is considered alive after two successful checks, dead after three failures.

nginx upstream as an Alternative

upstream bitrix_backends {
    round_robin;
    server 10.0.0.11:80 weight=1 max_fails=3 fail_timeout=30s;
    server 10.0.0.12:80 weight=1 max_fails=3 fail_timeout=30s;
    keepalive 32;
}

server {
    listen 443 ssl;

    location / {
        proxy_pass http://bitrix_backends;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        client_max_body_size 256m;
        proxy_read_timeout 120s;
    }
}

keepalive 32 — persistent connections between nginx and backends. Without keepalive, each request opens a new TCP connection to PHP-FPM — unnecessary overhead.

How to Configure Health Checks for Bitrix?

A health check is an HTTP request verifying that a backend is alive. For Bitrix we use the script /bitrix/admin/cluster_check.php, which returns 200. HAProxy is configured as:

option httpchk GET /bitrix/admin/cluster_check.php
http-check expect status 200

Check interval — every 5 seconds. After two successful checks the node recovers, after three failures it goes DOWN. We also recommend checking PHP-FPM and MySQL ports for full monitoring.

Proxying File Uploads

Uploading large files (prices 100+ MB, videos) through the balancer requires configuration:

proxy_request_buffering off;
proxy_max_temp_file_size 0;
client_max_body_size 512m;
proxy_read_timeout 600s;

Without proxy_request_buffering off, nginx buffers the entire uploaded file in memory — for a 512 MB file and 10 concurrent uploads, that's 5 GB of RAM just for buffers.

Forwarding the Real IP to Bitrix

Bitrix uses the user's IP for sessions and restrictions. Without configuration, it sees the balancer's IP. In /bitrix/php_interface/init.php add:

if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}

HAProxy forwards the real IP via X-Forwarded-For, nginx via X-Real-IP. We synchronize the balancer settings and init.php.

Typical Cluster Diagram
  • Frontend HAProxy (2 instances with keepalived)
  • 2–5 web nodes with mod_xsendfile
  • 1 dedicated node for push server
  • 1 master node for admin panel and agent tasks
  • 1 DB server (or MySQL cluster)

What's Included in the Load Balancing Setup

  • Audit of current architecture and load
  • Selection of balancer and algorithm based on tasks
  • Server configuration (HAProxy/nginx, health checks, keepalived)
  • Configuration of real IP forwarding and sessions
  • Optimization of file uploads and buffering
  • Integration with push server and admin panel
  • Testing under peak load
  • Documentation of scheme and parameters
  • Training of the administration team
  • 30 days of support after launch

Our Experience and Guarantees

Over a decade of configuring 1C-Bitrix clusters. More than 500 implemented projects — from small stores to large catalogs with millions of products. We guarantee stable cluster operation and provide post-implementation support. Get an engineer consultation and a detailed audit of your current architecture. Place your order — and your site will handle any traffic spikes.

1C-Bitrix Clustering

Imagine: a flash sale, 10,000 users simultaneously on the site, the server goes down with a 502 error, carts disappear, managers call support. We have seen this dozens of times. The solution is clustering: load balancing between servers, database replication, and automatic failover. Order an audit of your current infrastructure — in 2 days we will determine if and what kind of cluster is needed. Our experience: 40+ high-load projects on Bitrix.

Why is 1C-Bitrix clustering critical for fault tolerance?

80-90% of requests in a typical project are SELECT. Catalog, product pages, filters — all reads. Master-slave replication routes SELECTs to slave servers, leaving the master for writes only. The 'Web Cluster' module (Business edition and higher) routes requests automatically.

Common stumbling blocks: on master binlog_format = ROW. STATEMENT-based replication with NOW() or UUID() causes inconsistencies — leading to a week of debugging. Unique server-id, binary log enabled. On slave — read_only = ON, relay-log. Initialization via xtrabackup (not mysqldump, which locks tables for half an hour on a 20 GB database).

Metric #1 — Seconds_Behind_Master. If a slave lags by 5+ seconds, a customer places an order, returns to their personal account — and the order is missing (SELECT went to a lagging slave). The module allows manual exclusion of critical queries from slave routing.

Failover: Orchestrator or ProxySQL promote a slave to master in 15-30 seconds. The module supports up to 9 slave connections with configurable weights. Integrity check — pt-table-checksum from Percona Toolkit. Savings from inefficient infrastructure can be up to 40% of the budget, representing a significant annual amount for projects with 50,000+ unique visitors. For more information on replication, refer to MySQL Replication Documentation and Wikipedia: Database Replication.

When is clustering necessary?

Not every project needs it. Specific markers:

  • 50,000-100,000 unique visitors per day — a single server starts returning 502 errors during peak hours
  • Peak spikes of 5-10 times (sales, flash sales) — load grows in minutes, vertical scaling is not enough
  • SLA 99.9% (no more than 8.7 hours of downtime per year) — unattainable with a single server
  • Geographic distribution of users

Sometimes composite caching, SQL optimization, and vertical scaling are sufficient. We will honestly tell you if a cluster is not yet needed. Investments in clustering typically pay off within 3-6 months under peak loads. The average project budget is determined individually.

What does the cluster architecture consist of?

Load balancer. HAProxy, nginx upstream, or cloud LB. Round-robin for even distribution, ip-hash for session stickiness, least connections for adaptive balancing. Health checks remove dead servers from the pool. SSL termination on the balancer offloads web nodes.

Web servers. Identical nginx + php-fpm, each with a full copy of the code. Sessions in Redis/Memcached, not on disk (otherwise users lose their cart when switching servers). In the cloud — auto-scaling: load increases — servers are added, load decreases — they are removed.

Cache. Redis Cluster with data sharding across nodes. Redis Sentinel for small clusters. Memcached is fast but lacks persistence. Configuration in .settings.php — servers, weights, sharding strategy.

File storage. Uploads, images — accessible from each node. NFS for 2-3 servers, but it is a single point of failure. GlusterFS — distributed file system without single point of failure. S3 (MinIO, AWS, Yandex Object Storage) — offload static files to object storage, the Bitrix module works out of the box.

How to ensure failover at each cluster level?

Level Mechanism RTO
Load balancer Keepalived + VRRP < 5 sec
Web servers Health check < 10 sec
MySQL master Orchestrator / ProxySQL < 30 sec
MySQL slave Removal from pool < 5 sec
Redis Sentinel / Cluster failover < 15 sec
Files GlusterFS replication Automatic

The cluster is 5 times more reliable than a single server — if any node fails, the service continues to operate.

What are common clustering setup mistakes?

  • Sessions on files — when a server goes down, users lose cart and authentication.
  • Unmonitored Seconds_Behind_Master — sales suffer and SLA is unmet.
  • Single point of failure at the file storage level (NFS without replication).
  • Lack of replication monitoring — data inconsistencies go undetected.

We include checks for all these points in our audit and testing.

What is the clustering process?

  1. Load audit — load profile, bottlenecks, load testing. We find the ceiling of a single server.
  2. Design — components tailored to requirements and budget. Not everyone needs GlusterFS — sometimes NFS and backups suffice.
  3. Infrastructure — servers, network, firewalls. Ansible for automation — any node can be recreated in minutes.
  4. Migration — transfer with minimal downtime. Components are connected sequentially, each step verified.
  5. Testing — simulation of peak conditions. We crash the master, disconnect a web server, kill Redis — see how the system behaves.
  6. Documentation — architecture diagram, runbook, disaster recovery plans.

What does clustering work include?

Deliverable Description
Current load audit Request profile, bottlenecks, load testing
Project documentation Architecture diagram, runbook, disaster recovery plan
Infrastructure Server, network, firewall setup (Ansible)
Migration Transfer with minimal downtime, phased component connection
Testing Simulation of peak conditions: crash master, disconnect web server, kill Redis
Team training Documentation, 2 weeks of post-implementation consultations
Warranty 6 months of correct cluster operation — if something goes wrong, we fix it within 24 hours

What are the typical timelines?

Task Timeline
Audit and design 1-2 weeks
Basic cluster (2 web + master-slave MySQL) 2-3 weeks
Full cluster with failover at all levels 4-6 weeks
Monitoring + load testing 2-4 weeks

Contact us to get an engineer consultation and a preliminary project estimate within 2 days. We will calculate the cost based on your specific needs. Order an audit to find out the exact architecture and budget.