Expand my Community achievements bar.

SOLVED

AEM Dispatcher Multi Environment Usage

Avatar

Community Advisor

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.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.ht... for more details.
Regards
Albin

View solution in original post

4 Replies

Avatar

Level 3

Hi @iamnjain,

 

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

-Vikas Chaudhary

Avatar

Level 4

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

Avatar

Community Advisor

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-a... 

  • Environment Variables in AEMaaCS
  • Environment Variables in AMS
  • Leveraging Global Environment Variables:

Aanchal Sikka

Avatar

Correct answer by
Community Advisor

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.ht... for more details.
Regards
Albin