AEM Dispatcher Multi Environment Usage | Community
Skip to main content
iamnjain
New Participant
January 5, 2024
Solved

AEM Dispatcher Multi Environment Usage

  • January 5, 2024
  • 4 replies
  • 1484 views

Hello People,

 

We have different environments in project and different vhost and farm file for each environment domain.

Since most of things are common in these, how can we merge into one and handle environment specific values using vars file?

 

Any suggestion would be helpful.
Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AlbinIs1

You can follow some of the below patterns to support different environments through same set of configuration files.

 
www_example_com.vhost
 
<VirtualHost *:80>
        ServerName    "www.example.com"
        ServerAlias   "www.example.com"   "exampledotcom-dev.test.com" "exampledotcom-uat.test.com" "exampledotcom-stage.test.com"
....
 
<Location />
        <If "'${ENV_TYPE}' =~ m#(dev|uat|stage)#">
....
        </If>
    </Location>
</VirtualHost>
 
Also in rewrite file use variables to support environment specific redirects(may be vanity redirect you can keep the live URL)
 
www_example_com.rules
 
e.g
 
RewriteRule  ^/$                 %{HTTP:X-Forwarded-Proto}://%{SERVER_NAME}/us/en/home.html [R=301,L]
RewriteRule "^/test$" "%{HTTP:X-Forwarded-Proto}://%{SERVER_NAME}/test_page.html" [R=301,NC,NE,L]
 
Also in available farms, virtualhost configuration
 
www_example_com.farm
 
/virtualhosts {
"exampledotcom-dev.test.com"
"exampledotcom-uat.test.com"
"exampledotcom-stage.test.com"
}
 
The ENV_TYPE variable is predefined in AMS, and its value can be customized by coordinating with an Adobe CSE. AEM as a Cloud Service introduces the ENVIRONMENT_TYPE variable, with possible values being 'development' (irrespective of the number of development environments enabled or their designated purposes), 'stage', or 'production'. Additionally, AEM as a Cloud Service provides flags such as ENVIRONMENT_DEV, ENVIRONMENT_STAGE, and ENVIRONMENT_PROD. Custom variables can be defined within global or environment-specific variable files. Furthermore, AEM as a Cloud Service allows the use of variables defined in the Cloud Manager within dispatcher configurations, refer to https://www.albinsblog.com/2023/09/support-custom-run-modes-in-aem-as-a-cloud-env-specific-values.html for more details.
Regards
Albin

4 replies

AlbinIs1Accepted solution
New Participant
January 7, 2024

You can follow some of the below patterns to support different environments through same set of configuration files.

 
www_example_com.vhost
 
<VirtualHost *:80>
        ServerName    "www.example.com"
        ServerAlias   "www.example.com"   "exampledotcom-dev.test.com" "exampledotcom-uat.test.com" "exampledotcom-stage.test.com"
....
 
<Location />
        <If "'${ENV_TYPE}' =~ m#(dev|uat|stage)#">
....
        </If>
    </Location>
</VirtualHost>
 
Also in rewrite file use variables to support environment specific redirects(may be vanity redirect you can keep the live URL)
 
www_example_com.rules
 
e.g
 
RewriteRule  ^/$                 %{HTTP:X-Forwarded-Proto}://%{SERVER_NAME}/us/en/home.html [R=301,L]
RewriteRule "^/test$" "%{HTTP:X-Forwarded-Proto}://%{SERVER_NAME}/test_page.html" [R=301,NC,NE,L]
 
Also in available farms, virtualhost configuration
 
www_example_com.farm
 
/virtualhosts {
"exampledotcom-dev.test.com"
"exampledotcom-uat.test.com"
"exampledotcom-stage.test.com"
}
 
The ENV_TYPE variable is predefined in AMS, and its value can be customized by coordinating with an Adobe CSE. AEM as a Cloud Service introduces the ENVIRONMENT_TYPE variable, with possible values being 'development' (irrespective of the number of development environments enabled or their designated purposes), 'stage', or 'production'. Additionally, AEM as a Cloud Service provides flags such as ENVIRONMENT_DEV, ENVIRONMENT_STAGE, and ENVIRONMENT_PROD. Custom variables can be defined within global or environment-specific variable files. Furthermore, AEM as a Cloud Service allows the use of variables defined in the Cloud Manager within dispatcher configurations, refer to https://www.albinsblog.com/2023/09/support-custom-run-modes-in-aem-as-a-cloud-env-specific-values.html for more details.
Regards
Albin
aanchal-sikka
New Participant
January 5, 2024

Hello @iamnjain 

 

Variables allow you to decouple environment-specific settings from configurations. By using variables to store environment-related values, you ensure that configuration files remain consistent across development, testing, and production environments, ensuring the same functional output in different scenarios.

 

Please refer to following sections on https://techrevelhub.wordpress.com/2023/08/28/navigating-aem-dispatcher-setup-farm-file-resolution-and-variable-utilization/#env-var-aemaacs 

  • Environment Variables in AEMaaCS
  • Environment Variables in AMS
  • Leveraging Global Environment Variables:
Aanchal Sikka
New Participant
January 5, 2024

Hello @iamnjain 

 

create an Ansible template of your vhost and farm files where variable or environment-specific content is replaced with a placeholder.

<VirtualHost *:80>
ServerAdmin {{ server_admin }}
...
DocumentRoot /var/www/{{ document_root }}
...
</VirtualHost>

 

Then Definevariables in var files for instance prod_vars.yml , QA_vars.yml

 

Hope this helps.

 

Thanks,

Venkat

VikasChaudhary_
New Participant
January 5, 2024

Hi @iamnjain,

 

Can you please share a few differences among these environment specific vhost and farm files?

-Vikas Chaudhary