Expandir la barra de logros de la comunidad.

AEMaaCS how to use Macro in dispatcher

Avatar

Level 2

Please guide on how to use Macro in AEMaaCS  dispatcher.

In which folder we should declare Macro and how to call it in Vhost ?

 

We are using Multi-site setup, need multiple vhost files and how to make it generic and use Macro 

https://httpd.apache.org/docs/2.4/mod/mod_macro.html#use

Checked above document, but not sure how to make a complete vhost as a Macro and how to call it in enabled vhosts folder?

 

Can we call a Macro within a Macro?

Can we create full  vhost using Macro instead of creating Macro just to include Rewrite rules?

Temas

Los temas ayudan a categorizar el contenido de la comunidad e incrementan la posibilidad de encontrar contenido relevante.

3 Respuestas

Avatar

Level 10

Apache mod_macro is fully supported in AEMasCS Dispatcher, and here you can find a good guide to walk you through: https://www.aemguide.in/?m=0 

You can declare macros in the conf.d/available_vhosts folder structure. For example:​

  1. Create a dedicated macro definition file: conf.d/available_vhosts/macros.conf or conf.d/available_vhosts/vhost_macros.conf

  2. Place individual macro definitions in this file

  3. Include this macro file at the top of your vhost configuration files

Structure of your dispatcher configuration:

dispatcher/
├── conf.d/
│   ├── available_vhosts/
│   │   ├── macros.conf (macro definitions)
│   │   └── site_template.vhost (optional template)
│   └── enabled_vhosts/
│       ├── site1.vhost (uses macro)
│       ├── site2.vhost (uses macro)
│       └── site3.vhost (uses macro)
├── conf.dispatcher.d/
│   ├── available_farms/
│   └── enabled_farms/
│       ├── site1_farm.any
│       ├── site2_farm.any
│       └── site3_farm.any

 

I never tried before, but you should be able to call nested macros:

<Macro CommonRewriteRules $sitename>
  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/dispatcher/invalidate.cache
  RewriteRule ^/$ /content/$sitename/home.html [PT,L]
</Macro>

<Macro FullVHost $sitename $domain $docroot>
  <VirtualHost *:80>
    ServerName $domain
    DocumentRoot $docroot
    
    <Directory $docroot>
      <IfModule disp_apache2.c>
        SetHandler dispatcher-handler
      </IfModule>
    </Directory>
    
    # Call nested macro
    Use CommonRewriteRules $sitename
    
    ErrorLog logs/$sitename-error.log
  </VirtualHost>
</Macro>

 

 

Avatar

Level 2

@giuseppebaglio 

observing error during deployment 

Syntax error on line 34 of /etc/httpd/conf.d/enabled_vhosts/01_brandA.vhost: no macro defined before Use

But '1_macros.conf' is already defined  in available_vhosts 

Avatar

Level 10

Are you importing the 1_macros.conf file with the Include directive?