I have an old Apache PHP web site that I am in the process of upgrading. In the interim, I need to continue to access this site via a URL "legacy.example.com"
I have added a ServerAlias entry to the site's .conf file. When I go to "https://legacy.example.com" I am pointed to an incorrect folder and the what loads is a completely different site, but still a site on my system. But when I go to the original "https://example.com", I am pointed at the correct folder and the site loads as normal.
This is being hosted on an AWS EC2 instance, and the domain name example.com points at an elastic IP while legacy.example.com points to the configured public IP of the EC2 instance (the elastic iP is going to be moved to the new site, soon, and so it would be the wrong IP for legacy at that point)
I have the following configuration file (aside from the addition of the ServerAlias, this configuration has worked, as-is, for a VERY long time):
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot "/path/to/sites/folder/www-root/"
ServerName example.com # This address goes to the correct root folder
ServerAlias legacy.example.com # This address goes to an incorrect folder
ErrorLog /path/to/error/log
CustomLog /path/to/access/log combined
<Directory "/path/to/sites/folder">
Options FollowSymLinks ExecCGI
AllowOverride None
Require all granted
</Directory>
SetEnv APP_ROOT "/path/to/sites/folder"
php_value auto_prepend_file "/path/to/sites/folder/etc/bootstrap.php"
php_value magic_quotes_gpc "0"
php_value error_log "/path/to/sites/folder/log/php.log"
# SSL setup
SSLCertificateFile <stuff>
SSLCertificateKeyFile <stuff>
SSLCertificateChainFile <stuff>
</VirtualHost>
</IfModule>
As far as I can tell, there is no conflict in my Apache conf files:
My apachectl -S output: (The port 80 legacy.example.com is a permanent redirect to port 443)
VirtualHost configuration:
*:443 is a NameVirtualHost
default server example.com (/etc/apache2/sites-enabled/example-ssl.conf:7)
port 443 namevhost example.com (/etc/apache2/sites-enabled/example-ssl.conf:7)
alias legacy.example.com
port 443 namevhost www.example.com (/etc/apache2/sites-enabled/www.example.com- ssl.conf:1)
*:80 is a NameVirtualHost
default server unrelatedsite.com (/etc/apache2/sites-enabled/unrelatedsite.com.conf:7)
port 80 namevhost unrelatedsite.com (/etc/apache2/sites-enabled/unrelatedsite.com.conf:7)
port 80 namevhost www.unrelatedsite.com (/etc/apache2/sites-enabled/unrelatedsite.com.conf:25)
port 80 namevhost legacy.example.com (/etc/apache2/sites-enabled/legacy.example.conf:6)
port 80 namevhost example.com (/etc/apache2/sites-enabled/example.conf:6)
port 80 namevhost www.example.com (/etc/apache2/sites-enabled/www.example.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=##
Group: name="www-data" id=##
Why might one address go to one folder, and another address go to another given the same config file?
Edit: Another curious behavior... When I hit legacy.example.com, I see no changes to the access log. But when I hit example.com, I do.