Apache Configuration for 1C-Bitrix
Apache remains a common choice for Bitrix — especially in the official Bitrix Environment, where it runs alongside Nginx (Apache handles PHP, Nginx sits in front as a reverse proxy). Configuring Apache without understanding Bitrix-specific behavior leads to issues with .htaccess, the mod_rewrite module, and performance.
Apache as a Backend Behind Nginx
In Bitrix Environment, the standard setup is: Nginx listens on 80/443 and proxies PHP requests to Apache (port 8080):
# nginx: forward PHP to Apache
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 accepts the request and processes it via mod_php or mod_proxy_fcgi (PHP-FPM). In this setup, Apache does not serve static files — Nginx delivers them directly.
VirtualHost Configuration
<VirtualHost *:8080>
ServerName example.com
DocumentRoot /var/www/bitrix
<Directory /var/www/bitrix>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Accelerate PHP via FPM
<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>
AllowOverride All — required for Bitrix .htaccess to work. Without it, SEF URLs (urlrewrite) will not function.
Bitrix .htaccess and mod_rewrite
Bitrix generates .htaccess automatically when SEF URLs are enabled. The core rules:
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>
mod_rewrite must be enabled: a2enmod rewrite && systemctl reload apache2.
Blocking Service Directories
# In /var/www/bitrix/bitrix/.htaccess
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
# Prevent PHP execution in the upload directory
<Directory /var/www/bitrix/upload>
<FilesMatch "\.php$">
Require all denied
</FilesMatch>
</Directory>
Apache Performance for Bitrix
MPM event + PHP-FPM — the recommended combination for production:
# /etc/apache2/mods-enabled/mpm_event.conf
<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 1,000 requests. This is the equivalent of pm.max_requests in PHP-FPM and guards against memory leaks in mod_php.
Case Study: .htaccess and AllowOverride Conflict
A site migration: SEF URLs worked on the old hosting but on the new server all URLs except the homepage returned 404. mod_rewrite was enabled and .htaccess was in place. Cause: AllowOverride None in the default Apache 2.4 Ubuntu config. A single line AllowOverride All in the VirtualHost fixed the problem. Rule of thumb: after any migration, always verify AllowOverride in the Apache configuration.
Estimated time to configure Apache for Bitrix: 0.5–1 day.







