I'm currently migrating a bunch of websites to amazon ec2 (running on the Amazon Linux AMI), and am having difficulties getting Apache's VirtualHost configuration to work.
Here's what my httpd.conf file looks like:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/sites/example.com/
<Directory /home/sites/example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/example.com.error.log
LogLevel warn
CustomLog /var/log/httpd/example.com.access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /home/sites/blog.example.com/
<Directory /home/sites/blog.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/blog.example.com.error.log
LogLevel warn
CustomLog /var/log/httpd/blog.example.com.access.log combined
</VirtualHost>
Here's the result of httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 example.com (/etc/httpd/conf.d/ssl.conf:74)
*:80 is a NameVirtualHost
default server example.com (/etc/httpd/conf/httpd.conf:1012)
port 80 namevhost example.com (/etc/httpd/conf/httpd.conf:1012)
port 80 namevhost blog.example.com (/etc/httpd/conf/httpd.conf:1029)
Syntax OK
However, if I attempt to go to blog.example.com, I get a ERR_NAME_NOT_RESOLVED response.
If I change the first VirtualHost definition to blog.example.com, I can load the blog.example.com site, so both sites are working, leading me to suspect I either have configured something wrong in VirtualHost, or on the end of my domain registrar.
My issue was that I had the example.com domain before the blog.example.com domain, meaning everything just went to example.com. Order matters!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.