0

I have an Apache server running on an AWS EC2 instance. Currently, one virtual host is running successfully on the server, and I want to add a second virtual host / domain, but I can't figure out how to get it working.

Anonymizing the data, here's the original information I added to httpd.conf to get the first virtual host running:

<Directory "/var/www/site-1/public">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<VirtualHost *:80>
    DocumentRoot "/var/www/site-1/public"
    ServerName "site-1.com"
    ServerAlias "*.site-1.com"
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =site-1.com [OR]
    RewriteCond %{SERVER_NAME} =*.site-1.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

I then have the following registed in Google Domains for site-1 (with a fake IP address):

Host name     Type  TTL      Data
site-1.com    A     1 hour   4.184.56.145
*.site-1.com  A     1 hour   4.184.56.145

I then used Certbot to add an SSL cert, which added the following line to httpd.conf and an ACME challenge to the Google Domains DNS settings:

Include /etc/httpd/conf/httpd-le-ssl.conf

This is all working fine. I then purchased a second domain (site-2.com), and for now, I'm just trying to get the virtual host running with a very simple index.html file in the root of the site directory (i.e., /var/www/site-2).

For that, I added the following at the very bottom of httpd.conf:

<Directory "/var/www/site-2">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<VirtualHost *:80>
    DocumentRoot "/var/www/site-2"
    ServerName "site-2.com"
</VirtualHost>

And the following DNS settings were added to Google Domains for site-2:

Host name     Type  TTL      Data
site-2.com    A     1 hour   4.184.56.145

It's been several hours since all these settings were added for site-2, and I restarted the Apache server several times with sudo systemctl restart httpd. However, when I go to site-2.com, I get the following page, which is not the sample index.html file I placed under /var/www/site-2:

enter image description here

It's also worth noting that the favicon for site-2 is actually the favicon for site-1. Not sure why. In addition, the directory/file permissions/ownership for site-2 is the same as for site-1.

Can anyone provide any ideas for why this isn't working? For what it's worth, after doing quite a bit of research, I thought I had to add the following line to httpd.conf, but doing so and restarting the server doesn't make a difference:

NameVirtualHost *:80

Edit: I just figured something out. For whatever reason, site-2 is pointing to the var/www/html directory. If I put a sample index.html file into that directory, then it loads correctly when I go to site-2.com. Why is that? Why is the following virtual-host block not working?

<VirtualHost *:80>
    DocumentRoot "/var/www/site-2"
    ServerName "site-2.com"
</VirtualHost>
HartleySan
  • 103
  • 4
  • Are you actually getting site-1 instead of site-2? Is site-2.com resolvable? If not for testing add it in your testing machine hosts file. According to Apache http docu, put `Listen 80` on top of your configuration. – dexter Dec 05 '22 at 15:35
  • No, I don't get `site-1` instead of `site-2` for site-2.com. I get the Apache Test Page shown above when I go to site-2.com. I have a bunch of virtual hosts running on my local machine, and they all work fine. I already have `Listen 80` at the top of the `httpd.conf` file. Thanks for your suggestions, dexter, but not sure if any of that changes anything. – HartleySan Dec 05 '22 at 15:39

1 Answers1

0

Honestly don't know what the deal is, but it just started working. Maybe it was a DNS propagation issue (not sure), but the config I listed in my original question started working.

HartleySan
  • 103
  • 4