10 June 2013

CPanel on AWS: Domains redirecting to cgi-sys/defaultwebpage.cgi

We recently set up a test server environment on AWS. One of the issues we faced was putting multiple domains on a shared ip address. Visiting these domains redirected to the default web page for the hostname.

Our Setup:
An Elastic IP (EIP) pointing to a VPC which contained an EC2 instance (web server) and an RDS instance (mysql server). WHM/cpanel had DNS Clustering enabled for automatic DNS entries on our remote nameservers and the shared IP address was set to the EIP.

Process:
After much googling about the problem and a lot of test edits to httpd.conf it seemed apparent that it was related to a resolution of the domain name on the web server. The DNS entry itself was correct as we could reach the server but it didn't seem like it was resolving to the correct ip address that was within the VirtualHost directive in httpd.conf.

I created a simple PHP script in the default htdocs location to print out the environment.  This was simply something like:
<?php print_r($_ENV);
This gave me the information I needed (although I missed it for many hours). $_ENV['SERVER_ADDR'] was set to an internal ip address not the EIP.

The reason is the EIP points to the VPC which in turn passes the request to the internal server IP address - in our case a 10.0.x.x address. The server was then responding with the default configuration not the settings within the respective VirtualHost directive (as it was set to use the EIP).

Solution:
In our case we still have the EIP set as the shared IP address in WHM/cpanel. We do this so that the clustering will set up the DNS entries correctly. However we need to manually change the VirtualHost entries to respond to the internal IP address. (The plan is to write a post-account-setup script to automatically change on account creation).