When you build Nginx on EC2 with multiple server names support. It is pretty straight-forward to configure Route53 to alias or CNAME the domain names to ELB. However, if the ELB is behind the CloudFront and we need CloudFront to serve multiple custom domain names. What should we do?
Well, just alias or CNAME the domain name to CloudFront is not enough. You probably consider to modify Alternate Domain Names (CNAMEs) but it’s not gonna work either. Please note CloudFront by default will NOT forward headers to the origin, hence requests getting through ELB will not carry correct Host header and Nginx behind ELB will fail to determine by the header properly.
By adding Host header into the Whitelist Headers, along with other CloudFront-* headers, you can not only determine the Host info properly in Nginx but also benefit with extra useful headers passed from CloudFront.
Consider the following configuration.