# example.com web site

# See notes at end of file.

# SSL/TLS only for this site (no cleartext port 80)
<VirtualHost *:443>

SSLEngine on

ServerName  example.com
ServerAdmin webmaster@example.com

DocumentRoot /srv/web/example.com/

ErrorLog    logs/example.com/error
TransferLog logs/example.com/access

# RoundCube supplies a set of standard Apache config we'll use.
Include /etc/roundcube/apache.conf

<Directory /srv/web/example.com/>
	Options +FollowSymLinks
	Require all granted
</Directory>

# index.html must come first.  If index.php comes first Apache of course tries
# that first, and any *.php gets grabbed by ProxyPassMatch, and if PHP-FPM
# does not find index.php it generates its own "file not found" error page,
# and Apache sees that as valid page content to return to the HTTP client, and
# thus Apache never goes looking for index.html as a fallback.
DirectoryIndex index.html index.php

# This sends all *.php files to PHP FPM for execution.
ProxyPassMatch \
	\.php$ \
	unix:/run/php/roundcube.sock|fcgi://localhost/srv/web/roundcube \
	max=10 \
	acquire=10 \
	enablereuse=On \
	retry=10 \
	ttl=120

# max=X		should match pm.max_children=X in FPM pool config
# acquire=X	return SERVER_BUSY if waiting for proxy pool > X sec
# enablereuse	mod_proxy_fcgi is opt-in
# retry=X	retry connect to FPM after X seconds
# ttl=X		if idle for X seconds, close

# We use ProxyPassMatch to intercept all requests for *.php files,
# and send them to PHP-FPM using mod_proxy_fcgi.
# PHP-FPM is a PHP runtime host, the way mod_php is, but running independent
# of the Apache process.  By running PHP outside Apache, we can restart
# PHP independently, we keep PHP issues separate from Apache, we can run
# individual PHP website apps in different contexts (memory, security), etc.
# FastCGI is the interface spec between PHP-FPM and mod_proxy_fcgi.

# Tried using an Alias directive to put RoundCube under a subdir.
# https://www.example.com/roundcube/
# However with ProxyPassMatch, Apache passes the URL path through
# to FastCGI, which doesn't work.  For example the top-level
# /roundcube/index.php
# became /var/lib/roundcube/public_html/roundcube/index.php by the time FPM
# went looking for a file.
#
# I could work around that by using a RewriteRule and the [proxy] flag, but
# that causes everything to get funneled through a single Apache proxy worker.
# I wanted this to be able to scale if I ever needed it to.
#
# A symlink in the doc root to the proper directory works.  That makes the URL
# and filesystem paths line up properly.

</VirtualHost>
