# Configure ServerAdmin and ServerName
ServerName localhost
ServerAdmin webmaster@localhost

# Enable HTTP2
Protocols h2 http/1.1

SSLProtocol -all +TLSv1.2 +TLSv1.3

# Set CloudFlare Real IP
RemoteIPHeader CF-Connecting-IP

# Configure main document root
DocumentRoot ${APACHE_DOCUMENT_ROOT}

# Set basic settings for document root. Configure correct directory indexes and disable directory browsing
<Directory ${APACHE_DOCUMENT_ROOT}>
    AllowOverride All
    Require all granted
    Options -Indexes +FollowSymLinks +MultiViews
    DirectoryIndex index.php index.html index.htm
</Directory>

# Healthchecks: Set /healthcheck to be the healthcheck URL
ProxyPass "/healthcheck" "fcgi://localhost:9000"
ProxyPassReverse "/healthcheck" "fcgi://localhost:9000"

# For any files that match PHP, pass it to PHP-FPM for processing
<FilesMatch "\.php$">
    # 2.4.10+ can proxy to unix socket
    ProxyFCGIBackendType GENERIC
    SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>

# Set the Proxy Timeout to be 30 minutes
ProxyTimeout 1800

# Set environment variable for healthcheck requests
SetEnvIf Request_URI "^/healthcheck$" dontlog

# CustomLog directive to conditionally log requests
LogFormat "%l %u %t %v %a \"%r\" %>s %b" comonvhost
CustomLog /dev/stdout comonvhost env=!dontlog

# Configure Log Settings
ErrorLog /dev/stderr
LogLevel ${LOG_OUTPUT_LEVEL}

# Disable Server Signature for increased security
ServerSignature Off

# SSL Settings
SSLEngine on
SSLCertificateFile ${SSL_CERTIFICATE_FILE}
SSLCertificateKeyFile ${SSL_PRIVATE_KEY_FILE}
