Apache Configuration for 1C-Bitrix
Apache remains the standard choice for Bitrix—especially in the official Bitrix Environment, where it works alongside Nginx (Apache handles PHP, Nginx serves static files). But without proper configuration, the setup becomes a source of bugs: performance drops, SEF URLs stop working, and sensitive directories become accessible. Over 7 years, we've compiled an optimal config that we use across all projects—turnkey, with a stability guarantee. Our configuration increases server response speed by up to 20% and reduces CPU load by 30%.
Apache as Backend Behind Nginx
In Bitrix Environment, the standard architecture is: Nginx listens on port 80/443, proxies PHP requests to Apache (port 8080). Why this way and not the reverse? Because Apache excels at dynamic content, while Nginx is more efficient at serving static files and handling concurrent connections. Here's a minimal Nginx config:
location ~ \.php$ { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } Apache receives the request and processes it via mod_php or mod_proxy_fcgi (PHP-FPM). We strongly recommend PHP-FPM—it delivers a performance gain of up to 2x compared to mod_php (based on our load tests at 1000 requests/second). More details about Apache can be found on Wikipedia.
Virtual Host: VirtualHost Configuration
We create a separate VirtualHost for each site:
<VirtualHost *:8080> ServerName example.com DocumentRoot /var/www/bitrix <Directory /var/www/bitrix> Options -Indexes +FollowSymLinks AllowOverride All Require all granted </Directory> <FilesMatch "\.php$"> SetHandler "proxy:unix:/run/php/php8.1-fpm-bitrix.sock|fcgi://localhost" </FilesMatch> ErrorLog ${APACHE_LOG_DIR}/bitrix_error.log CustomLog ${APACHE_LOG_DIR}/bitrix_access.log combined </VirtualHost> The key line is AllowOverride All. Without it, Bitrix cannot use .htaccess for SEF URLs and composite cache. In our practice, we had a case: a client migrated to a new server, and all pages except the home page returned 404. The default Ubuntu Apache 2.4 config had AllowOverride None. One fix—and the site worked.
Additional security parameters for VirtualHost
<Directory /var/www/bitrix/upload> <FilesMatch "\.php$"> Require all denied </FilesMatch> </Directory> <Directory /var/www/bitrix/bitrix> Require all denied </Directory> Bitrix .htaccess and mod_rewrite
Bitrix generates a .htaccess when SEF URLs are enabled. Here's the basic content (it's created automatically, but we verify it manually):
Options -Indexes AddDefaultCharset UTF-8 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Bitrix composite (HTML cache) RewriteCond %{DOCUMENT_ROOT}/bitrix/html_pages/%{HTTP_HOST}/%{REQUEST_URI}/__index.html -f RewriteRule ^ /bitrix/html_pages/%{HTTP_HOST}/%{REQUEST_URI}/__index.html [L] # Redirect to urlrewrite.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L] </IfModule> Check that mod_rewrite is enabled: a2enmod rewrite && systemctl reload apache2. Without it, SEF URLs won't work.
Securing Sensitive Directories
Security is a vital part of the configuration. By default, directories like bitrix/modules, bitrix/tmp and others are accessible via the web. We close them:
# In /var/www/bitrix/bitrix/.htaccess <IfModule mod_authz_core.c> Require all denied </IfModule> # Deny PHP execution in upload <Directory /var/www/bitrix/upload> <FilesMatch "\.php$"> Require all denied </FilesMatch> </Directory> Apache Performance for Bitrix
MPM event + PHP-FPM—the recommended stack for production. Here are typical MPM settings:
<IfModule mpm_event_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxRequestWorkers 150 MaxConnectionsPerChild 1000 </IfModule> MaxConnectionsPerChild 1000—Apache restarts child processes after 1000 requests, analogous to pm.max_requests in PHP-FPM, protecting against memory leaks.
| MPM | Threads | Memory Usage | Recommendation |
|---|---|---|---|
| prefork | 1 thread per process | High | Only for mod_php, not for production |
| worker | Threads but with blocking | Medium | Obsolete |
| event | Async processing | Low | Best choice for PHP-FPM |
Load testing (our numbers): MPM event delivers 1.5–2x more requests per second at 300 concurrent users compared to worker.
Additional PHP-FPM settings:
| Parameter | Value | Effect |
|---|---|---|
| pm.max_children | 50 | Increases parallel processing |
| pm.start_servers | 5 | Fast startup |
| pm.min_spare_servers | 5 | Stability under low load |
| pm.max_spare_servers | 10 | Optimal memory consumption |
How to Double Apache Performance for Bitrix?
Combine three components: PHP-FPM + MPM event + correct .htaccess with composite cache. Avoid mod_php—it's inefficient under load. Ensure the VirtualHost config uses SetHandler for PHP-FPM, not AddType. Check PHP-FPM pool settings: pm.max_children should equal MaxRequestWorkers in Apache. Additionally, enable composite cache: in the Bitrix admin panel, go to "Settings > Product Settings > Module Settings > Performance > Composite Mode".
Why Use Apache as Backend Behind Nginx?
Apache excels at handling complex urlrewrite rules and is compatible with Bitrix modules (e.g., mod_security). Nginx wins on static content and concurrent connections. Together they deliver optimal performance. Moreover, Bitrix Environment officially supports this combination.
What's Included in Apache Configuration for Bitrix
Our certified specialists perform a full audit and configuration:
- Review of current Apache and Nginx configuration
- Setup of VirtualHost with proper PHP and FPM versions
- Enabling mod_rewrite, optimizing .htaccess
- Selection and tuning of MPM (we recommend event)
- PHP-FPM pool configuration (pm.max_requests, etc.)
- Securing sensitive directories, hardening security
- Composite cache configuration (Bitrix HTML Cache)
- Load testing and report
- Recommendations for server-side caching (Redis/Memcached)
Timeline: from 0.5 to 1 day. Cost is calculated individually—contact us for a free project assessment. We guarantee stable operation after configuration—over 7 years of experience and 50+ successful projects.
If you need Apache configuration from scratch or optimization of an existing setup, get in touch. Receive a consultation and a ready-to-use solution for your project.

