# Apache Load Balancer Configuration for ai.succhia.cz

# Load required modules
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule headers_module modules/mod_headers.so

# VirtualHost configuration for HTTPS (Port 443)
<VirtualHost *:443>
    ServerName ai.succhia.cz

    # Enable SSL
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/ai.succhia.cz/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/ai.succhia.cz/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/ai.succhia.cz/chain.pem

    # Harden SSL
    Header set Strict-Transport-Security "max-age=31536000"

    # Proxy Balancer Configuration
    <Proxy "balancer://myclusterhantani">
        # Balancer members with appropriate load factors
        BalancerMember "http://ai.kowa.localhost:4322" loadfactor=90 failover=on
        BalancerMember "http://ai.bozz.localhost:4321" loadfactor=10

        # Load balancing method
        ProxySet lbmethod=byrequests
    </Proxy>

    # Proxy settings for the root context
    <Location />
        ProxyPass "balancer://myclusterhantani"
        ProxyPassReverse "balancer://myclusterhantani"
    </Location>

    # General Proxy settings
    ProxyTimeout 10
    ProxyPreserveHost On

    # Log settings
    ErrorLog ${APACHE_LOG_DIR}/ai.succhia.cz-error.log
    CustomLog ${APACHE_LOG_DIR}/ai.succhia.cz-access.log combined

</VirtualHost>

# VirtualHost configuration for HTTP (Port 80)
<VirtualHost *:80>
    ServerName ai.succhia.cz

    # Redirect all HTTP requests to HTTPS
    Include /etc/apache2/my-includes/redirect-to-https.conf

    # Log settings
    ErrorLog ${APACHE_LOG_DIR}/ai.succhia.cz-error.log
    CustomLog ${APACHE_LOG_DIR}/ai.succhia.cz-access.log combined

</VirtualHost>