Skip to main content
NageshRaja
Level 5
Mar 17, 2025 1:55 PM UTC
Solved

Environment variables vs Custom vars in AEM Cloud

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}
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Rohan_Garg
Rohan_GargAccepted solution
Community Advisor
May 13, 2025 3:02 PM UTC

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

 

Rohan Garg

9 replies

Level 2
Mar 17, 2025 1:59 PM UTC

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

Translate
arunpatidar
Community Advisor
Community Advisor
Mar 17, 2025 4:33 PM UTC
giuseppebaglio
Level 10
Mar 17, 2025 2:09 PM UTC

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.

Translate
NageshRaja
Level 5
Mar 29, 2025 7:16 AM UTC

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.

Translate
konstantyn_diachenko
Community Advisor
Community Advisor
Mar 17, 2025 4:28 PM UTC

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.

Translate
Kostiantyn Diachenko, Community Advisor, Certified Senior AEM Developer, creator of free AEM VLT Tool, maintainer of AEM Tools plugin.
NageshRaja
Level 5
Mar 29, 2025 7:18 AM UTC

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.

 

Translate
kautuk_sahni
Level 9
Apr 1, 2025 12:05 PM UTC

@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!

Translate
Kautuk Sahni
Rohan_Garg
Community Advisor
Rohan_GargCommunity AdvisorAccepted solution
Community Advisor
May 13, 2025 3:02 PM UTC

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

 

Translate
Rohan Garg