Environment variables vs Custom vars in AEM Cloud | Community
Skip to main content
NageshRaja
March 17, 2025
Solved

Environment variables vs Custom vars in AEM Cloud

  • March 17, 2025
  • 5 replies
  • 1014 views

Hi All,

 

In our dispatcher configuration we have the below include for custom variables -

Include conf.d/variables/custom.vars
Define BRAND_HTTP https://abc.com

We are defining a variable BRAND_HTTP which is set to abc.com.

 

We are further using the same configuration to set the X-Frame-Options as seen below

Header set X-Frame-Options "ALLOW-FROM ${BRAND_HTTP}"

Now in the Cloud Manager, the environment variable BRAND_HTTP is pointing to xyz.com

However, in the request URL we are only seeing the abc.com from the variables.

@arunpatidar @estebanbustamante @aanchal-sikka @rohan_garg 

Shouldn't the environment variable configuration be getting precedence?

We are already using environment variables to setup variables for ServerName and ServerAlias as seen below -

ServerName  ${PUBLISH_BRAND_HOSTNAME}
Best answer by Rohan_Garg

Hi @nageshraja,

Sorry for the delay in response - I think behaviour comes down to how and where the variables are evaluated within the Dispatcher configuration versus Apache’s environment variable system.


Apache Configuration - 
Include conf.d/variables/custom.vars
Define BRAND_HTTP https://abc.com
Header set X-Frame-Options "ALLOW-FROM ${BRAND_HTTP}"

The issue is due to the difference between Apache Define and environment variables (SetEnv/ENV):

Define BRAND_HTTP https://abc.com hardcodes the value at Apache parse-time.

 

Even if the environment variable BRAND_HTTP=https://xyz.com exists in Cloud Manager or the process environment, it will not override the Apache Define.

 

The ServerName ${PUBLISH_BRAND_HOSTNAME} works because Adobe has patched the dispatcher pipeline to replace ${PUBLISH_BRAND_HOSTNAME} with the environment variable before deploying.

That substitution is part of the Cloud Manager variable interpolation, which is allowed in limited directives — like ServerName, ServerAlias, VirtualHost, etc. But not inside header values or arbitrary Apache directives like Header set.

 

I hope this helps!

 

Regards,

Rohan Garg

 

5 replies

March 17, 2025

can you try with the sytax as {env:your_variable_name}

arunpatidar
Community Advisor
Community Advisor
March 17, 2025
giuseppebaglio
New Member
March 17, 2025

The first check I recommend is to verify if the other variables expected for xyz.com are functioning correctly. If they are, the issue you are experiencing may be related to the order of the rules. In Apache, rules and configurations are evaluated in the order they are defined. If a configuration is listed earlier in the files, it may take precedence over later configurations unless it is explicitly overridden.

NageshRaja
March 29, 2025

Hi @giuseppebaglio, The other variables are defined in environment variable in cloud manager are giving expected value for xyz.com

However, the case with this BRAND_HTTP is unique as it is defined in the custom.vars.

We have removed the value defined in custom.vars to allow the environment variable value to be picked up.

konstantyn_diachenko
Community Advisor
Community Advisor
March 17, 2025

Hi @nageshraja,

 

As far as I know, Cloud Manager environment variables are not working on cloud dispatcher configuration. They don't have effect in config files.

 

I would suggest defining env variables in this way in custom.vars:

//this is a valud by default for prod Define BRAND_HTTP https://abc.com <IfDefine ENVIRONMENT_DEV> Define BRAND_HTTP https://dev-abc.com </IfDefine> <IfDefine ENVIRONMENT_STAGE> Define BRAND_HTTP https://stage-abc.com </IfDefine>

 

Best regards,

Kostiantyn Diachenko.

Kostiantyn Diachenko, Community Advisor, Certified Senior AEM Developer, creator of free AEM VLT Tool, maintainer of AEM Tools plugin.
NageshRaja
March 29, 2025

Hi @konstantyn_diachenko

 

We have defined the server name and aliases as below in vhosts file

ServerName  ${PUBLISH_ATMOSPHERE_HOSTNAME}

The value is defined in cloud manager environment variables and it is picking the value correctly.

 

kautuk_sahni
Community Manager
Community Manager
April 1, 2025

@nageshraja Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Kautuk Sahni
Rohan_Garg
Community Advisor
Rohan_GargCommunity AdvisorAccepted solution
Community Advisor
May 13, 2025

Hi @nageshraja,

Sorry for the delay in response - I think behaviour comes down to how and where the variables are evaluated within the Dispatcher configuration versus Apache’s environment variable system.


Apache Configuration - 
Include conf.d/variables/custom.vars
Define BRAND_HTTP https://abc.com
Header set X-Frame-Options "ALLOW-FROM ${BRAND_HTTP}"

The issue is due to the difference between Apache Define and environment variables (SetEnv/ENV):

Define BRAND_HTTP https://abc.com hardcodes the value at Apache parse-time.

 

Even if the environment variable BRAND_HTTP=https://xyz.com exists in Cloud Manager or the process environment, it will not override the Apache Define.

 

The ServerName ${PUBLISH_BRAND_HOSTNAME} works because Adobe has patched the dispatcher pipeline to replace ${PUBLISH_BRAND_HOSTNAME} with the environment variable before deploying.

That substitution is part of the Cloud Manager variable interpolation, which is allowed in limited directives — like ServerName, ServerAlias, VirtualHost, etc. But not inside header values or arbitrary Apache directives like Header set.

 

I hope this helps!

 

Regards,

Rohan Garg