Score:0

ServerAlias url goes to wrong file path

bt flag

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.

jp flag
Did you reload the configuration after the modifications?
Lassanter avatar
bt flag
Absolutely. Good call on checking, though.
ezra-s avatar
ru flag
It could be a dns issue, accesses are always logged, define a specific log file for each virtualhost, check names ips and see where the request lands, if it doesnt land anywhere, dns issue.
Lassanter avatar
bt flag
I'm not clear on how it might be a DNS issue. The domain name resolves to the correct IP address. For the sake of completeness I can certainly double check that the IP is correct, but I am not expecting much. I will comment, again, when I have done so.
Lassanter avatar
bt flag
I am not convinced that it is a "DNS issue" per se. However, by pointing the DNS record at Amazon's Elastic IP, I am able to get the correct web site. I'm still befuddled by the fact that the original address was still connecting to the server (I could change the Apache config file and see changes... I am as certain as I can be that I was connecting to the correct server), but simply serving the wrong folder. I guess I am going to have to cope with reworking the DNS after changing the instance to which the Elastic IP is associated. I was hoping to avoid that. Such is life.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.