Restrict ServerAlias domain in dispatcher based on environment | Community
Skip to main content
Level 2
November 13, 2024
Solved

Restrict ServerAlias domain in dispatcher based on environment

  • November 13, 2024
  • 2 replies
  • 671 views

Hi All,

 

I have a requirement to remove one domian name from  serveralias configuration from one specific environment.

 

We are using 4 domain names for serverAlias configuration in vhost , but in one of the domain name is matching the stage/prod domain url then i have to remove the particular domain name from serverAlias configuration.

 

I tried with something like this, but it's not working.

<If "${DomainA}=='stage.domain.com'">

ServerAlias ${DomainB} ${DomaiC} ${DomainD}

</If>

<Else>

ServerAlias ${DomainA} ${DomainB} ${DomaiC} ${DomainD}

</Else>

 

Could any of you please suggest how to implement this requirement.

 

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 konstantyn_diachenko

Hi @prashanth55 ,

If you need to provide a different configuration for an environment try the following configuration.

customs.vars:

Define SERVER_ALIASES "${DomainA} ${DomainB} ${DomaiC} ${DomainD}" <IfDefine ENVIRONMENT_STAGE> Define SERVER_ALIASES "${DomainB} ${DomaiC} ${DomainD}" </IfDefine>

 vhost configuration:

ServerAlias ${SERVER_ALIASES}

 

Best regards,

Kostiantyn Diachenko.

2 replies

konstantyn_diachenko
Community Advisor
konstantyn_diachenkoCommunity AdvisorAccepted solution
Community Advisor
November 13, 2024

Hi @prashanth55 ,

If you need to provide a different configuration for an environment try the following configuration.

customs.vars:

Define SERVER_ALIASES "${DomainA} ${DomainB} ${DomaiC} ${DomainD}" <IfDefine ENVIRONMENT_STAGE> Define SERVER_ALIASES "${DomainB} ${DomaiC} ${DomainD}" </IfDefine>

 vhost configuration:

ServerAlias ${SERVER_ALIASES}

 

Best regards,

Kostiantyn Diachenko.

Kostiantyn Diachenko, Community Advisor, Certified Senior AEM Developer, creator of free AEM VLT Tool, maintainer of AEM Tools plugin.
A_H_M_Imrul
Community Advisor
Community Advisor
November 25, 2024

Hello @prashanth55,

Not sure if it's too late to answer.

But not sure how wise it would be to write logic in vhost config, rather you can do the following: 

- Create environment specific (dev2, dev, stage, prod) .vars files as follow:

 

/etc/httpd/conf.d/variables/domains_${ENV_TYPE}.vars //contains the following when: ENV_TYPE=dev2 or dev or prod Define DOMAINS "domain_a domain_b domain_c domain_d" //contains the following when: ENV_TYPE=stage Define DOMAINS "domain_b domain_c domain_d"

 

 - Add the .vars file in the vhost as follow (on top of the file):

 

Include /etc/httpd/conf.d/variables/domains_${ENV_TYPE}.vars

 

- Add the ServerAlias in the vhost file as as follow:

 

ServerAlias ${DOMAINS}

 

Points to note here is that: for AMS the ENV_TYPE variable needs to be configured in /etc/sysconfig/httpd file in the dispatcher server and for Cloud it needs to be configured via environment variable using cloud manager.

Thanks!