Reputation: 8088
On Amazon EC2, I have the following configuration:
<VirtualHost *:80>
ServerName a.example.com
ServerRoot /var/www/a.example.com
DocumentRoot html
</VirtualHost>
<VirtualHost *:80>
ServerName b.example.com
ServerRoot /var/www/b.example.com
DocumentRoot html
</VirtualHost>
<VirtualHost *:80>
ServerName c.example.com
ServerRoot /var/www/c.example.com
DocumentRoot html
</VirtualHost>
The problem is, that despite the above configuration being correct, all requests to any of the 3 domain names are being directed as if the request went to c.example.com
- as if the ServerName
values are just being ignored.
Anyone see a problem here?
Upvotes: 2
Views: 825
Reputation: 10849
ServerRoot
is allowed only in server config Context, not in VirtualHost
If you try to use it elsewhere, you'll get a configuration error that will either prevent the server from handling requests in that context correctly, or will keep the server from operating at all -- i.e., the server won't even start.
Upvotes: 1
Reputation: 8088
The problem I found, is that my build of Apache2:
Server version: Apache/2.4.18 (Amazon)
Server built: Mar 7 2016 22:32:11
Is not handling the DocumentRoot
parameter properly.
At the DocumentRoot config definition here, it says
If the directory-path is not absolute then it is assumed to be relative to the ServerRoot.
Well, this is apparently being ignored, because if I change the DocumentRoot
value as follows:
<VirtualHost *:80>
ServerName b.example.com
ServerRoot /var/www/b.example.com
DocumentRoot html
</VirtualHost>
To this:
<VirtualHost *:80>
ServerName b.example.com
ServerRoot /var/www/b.example.com
DocumentRoot /var/www/b.example.com/html #<-- updated
</VirtualHost>
Then the configuration works. I haven't tested to see if this is an issue with the core Apache build, or if it's with the Amazon version, either way, I hope this answer helps someone.
Upvotes: 0