<@sys.site id=siteId><#assign a=object/></@sys.site>
<@tools.disk>
<#assign
    realRootPath=rootPath?replace('\\','/')
    dynamicPath=a.dynamicPath?keep_after('//')?keep_before('/')?keep_before(':')
    dynamicLocation=a.dynamicPath?keep_after('//')?keep_after('/')
    dynamicPort=a.dynamicPath?keep_after('//')?keep_before('/')?keep_after(':')
    sitePath=a.sitePath?keep_after('//')?keep_before('/')?keep_before(':')
    siteLocation=a.sitePath?keep_after('//')?keep_after('/')
    sitePort=a.sitePath?keep_after('//')?keep_before('/')?keep_after(':')
/>
</@tools.disk>
            <textarea class="code" mode="xml">
#<@t.page 'server_config.apache_common_description'/>
<ifModule !proxy_module>
LoadModule proxy_module modules/mod_proxy.so
</ifModule>
<ifModule !proxy_balancer_module>
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
</ifModule>
<ifModule !headers_module>
LoadModule headers_module modules/mod_headers.so
</ifModule>
<#if dynamicLocation=siteLocation>
<ifModule !rewrite_module>
LoadModule rewrite_module modules/mod_rewrite.so
</ifModule>
</#if>
# https://tn123.org/mod_xsendfile/
<ifModule !xsendfile_module>
LoadModule xsendfile_module modules/mod_xsendfile.so
</ifModule>
<ifModule xsendfile_module>
    XSendFile on
    XSendFilePath ${realRootPath}/web/private/
</ifModule>

ProxyRequests off
ProxyPreserveHost On
<Proxy "balancer://cmsproxy">
    BalancerMember "http://localhost:8080" loadfactor=1
    ProxySet stickysession=JSESSIONID
</Proxy>

#${a.name} <@t.page 'server_config.site'/>
<Directory "${realRootPath}/web/site_${siteId}/">
    AllowOverride None
    Options FollowSymLinks Includes
    Require all granted
</Directory>

<VirtualHost *:${dynamicPort?has_content?then(dynamicPort,80)}>
    ServerName ${dynamicPath}
<@sys.domainList advanced=true siteId=siteId>
  <#if page.totalCount gt 0>
    ServerAlias <#list page.list as d><#if d.name!=dynamicPath&&d.name!=sitePath>${d.name}</#if><#if d.wild> *.${d.name}</#if><#sep> </#list>
  </#if>
</@sys.domainList>

#SSLEngine On
#SSLCertificateFile "conf/xxx.crt"
#SSLCertificateKeyFile "conf/xxx.key"

  <#if a.useSsi>
    alias /include/ "${realRootPath}/web/site_${siteId}/include/"
    AddType text/html .html .shtml
    AddOutputFilter INCLUDES .html .shtml
  </#if>

    RequestHeader set Sendfile X-Sendfile

    ProxyPass ${dynamicLocation?has_content?then('/'+dynamicLocation,'/')} balancer://cmsproxy${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}
    ProxyPassReverse ${dynamicLocation?has_content?then('/'+dynamicLocation,'/')} balancer://cmsproxy${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}

    <#if a?has_content && a.hasChild && a.multiple>
        <@sys.siteList parentId=a.id pageSize=100>
            <#list page.list as a>
                <#if a.directory?has_content>
    Alias ${siteLocation?has_content?then('/'+siteLocation,'/')}${a.directory}/ "${realRootPath}/web/site_${a.id}/webfile/"
                    <#if dynamicLocation=siteLocation>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://cmsproxy/%{REQUEST_URI} [P,L]
                    </#if>
                </#if>
            </#list>
        </@sys.siteList>
    </#if>

    <#if dynamicPath=sitePath&&dynamicPort=sitePort>
    #${a.name} <@t.page 'server_config.static'/>
    Alias "/${siteLocation}" "${realRootPath}/web/site_${siteId}/"
         <#if dynamicLocation=siteLocation>
    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT} %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT} %{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://cmsproxy/%{REQUEST_URI} [P,L]
        </#if>
    </#if>

    ErrorDocument 403 /error/403.html
    ErrorDocument 404 /error/404.html
    ErrorDocument 500 /error/500.html
    ErrorDocument 502 /error/500.html
    ErrorDocument 503 /error/500.html
    ErrorDocument 504 /error/500.html
</VirtualHost>

<#if dynamicPath!=sitePath||dynamicPort!=sitePort>
#${a.name} <@t.page 'server_config.static'/>
<VirtualHost *:${sitePort?has_content?then(sitePort,80)}>
    ServerName ${sitePath}
    <#if a.useSsi>
        <#if siteLocation?has_content>
    alias /include/ "${realRootPath}/web/site_${siteId}/include/"
    AddType text/html .html .shtml
    AddOutputFilter INCLUDES .html .shtml
        </#if>
    </#if>
    <#if a?has_content && a.hasChild && a.multiple>
        <@sys.siteList parentId=a.id pageSize=100>
            <#list page.list as a>
                <#if a.directory?has_content>
    #${a.name} <@t.page 'server_config.static'/>
    alias ${siteLocation?has_content?then('/'+siteLocation,'/')}${a.directory}/ "${realRootPath}/web/site_${a.id}/"
                </#if>
            </#list>
        </@sys.siteList>
    </#if>
    <#if siteLocation?has_content>
    Alias "/${siteLocation}/" "${realRootPath}/web/site_${siteId}/"
    <#else>
    DocumentRoot "${realRootPath}/web/site_${siteId}/"
    </#if>
    <IfModule headers_module>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
    ErrorDocument 403 /error/403.html
    ErrorDocument 404 /error/404.html
    ErrorDocument 500 /error/500.html
    ErrorDocument 502 /error/500.html
    ErrorDocument 503 /error/500.html
    ErrorDocument 504 /error/500.html
</VirtualHost>
</#if>
</textarea>