I've been really struggling with this for the past few days, and I'm at a lost. Here's what's going on.
I have an EC2 instance (Amazon Linux 2023) behind an ELB and a CloudFront distribution that I want to host two (or, eventually, more) subdomains using the VirtualHost
directive. However, no matter what I do, any request, no matter what the subdomain is, always goes right to the default document root (/var/www/html
).
All of the information I can find on similar setups always note to set Route 53 to the public IP address for the server, but, again, I'm trying to do this through CloudFront/an ELB. I don't want to use the public IP address for my instance; I want to use the regular subdomains I have picked out.
Here's the setup I have:
- Route 53 as an
A
record for both subdomains, both going to the CloudFront distribution URL - CloudFront is pointed at my ELB
- ELB has rules to send either
firstsd.mysite.com
orsecondsd.mysite.com
to the EC2 instance in question - I have a security certificate setup for the
mysite.com
domain
I've tried a number of different approaches.
First, I tried adding the VirtualHost
directives straight to httpd.conf in a bunch of different configurations. I tried keeping the VirtualHost blocks simplistic, like this:
<VirtualHost *:80>
ServerName firstsd.mysite.com
DocumentRoot "/var/www/html/firstsd"
</VirtualHost *:80>
<VirtualHost *:80>
ServerName secondsd.mysite.com
DocumentRoot "/var/www/html/secondsd"
</VirtualHost>
When this didn't work, I tried modifying it to this:
<VirtualHost *:80>
ServerName firstsd.mysite.com
DocumentRoot "/var/www/html/firstsd"
<Directory "/var/www/html/firstsd">
DirectoryIndex index.html index.php
Require all granted
AllowOverride all
Options Indexes FollowSymLinks
</Directory>
</VirtualHost *:80>
<VirtualHost *:80>
ServerName secondsd.mysite.com
DocumentRoot "var/www/html/secondsd"
<Directory "/var/www/html/secondsd">
DirectoryIndex index.html index.php
Require all granted
AllowOverride all
Options Indexes FollowSymLinks
</Directory>
</VirtualHost>
I also tried the above by changing the *:80
to *:443
and also duplicating it to cover both *:80
and *:443
.
The next thing I tried was to create new .conf files, as per the guide located here. I still got the same result: I ended up in the default home directory for my server.
Finally, I tried creating a brand new CloudFront distribution for each subdomain, adding /firstsd
and /secondsd
to the origin path option. Instead of hitting the default directory, I got a 403 error (which, admittedly, felt like progress on some level).
Any help on this would be greatly appreciated. Thanks!