<VirtualHost *:80>
    ServerName gitea._VAR_DOMAIN
    DocumentRoot /srv/www

    RewriteEngine On
    RewriteRule ^/?\.well-known/acme-challenge - [L]
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

    ErrorLog ${APACHE_LOG_DIR}/gitea-error.log
    CustomLog ${APACHE_LOG_DIR}/gitea-access.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerName gitea._VAR_DOMAIN
    # HTTP/2 is explicitly disabled due to long polling stalling other requests
    # https://github.com/go-gitea/gitea/issues/19265
    Protocols http/1.1
    DocumentRoot /srv/www

    SSLEngine on
    SSLCertificateFile /etc/ssl/acme-sh/gitea._VAR_DOMAIN.pem
    SSLCertificateKeyFile /etc/ssl/acme-sh/gitea._VAR_DOMAIN.key
    Header always add Strict-Transport-Security "max-age=15768000"

    AllowEncodedSlashes NoDecode
    ProxyPass / http://127.0.0.1:8802/ nocanon
    ProxyPreserveHost on
    ProxyRequests off

    ErrorLog ${APACHE_LOG_DIR}/gitea-error.log
    CustomLog ${APACHE_LOG_DIR}/gitea-access.log combined
</VirtualHost>
