我目前正在将一堆网站迁移到amazon ec2(在Amazon Linux AMI上运行),并且很难让Apache的VirtualHost配置工作。
这是我的httpd.conf文件的样子:
<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>
这是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
但是,如果我尝试访问blog.example.com,我会收到ERR_NAME_NOT_RESOLVED回复。
如果我将第一个VirtualHost定义更改为blog.example.com,我可以加载blog.example.com网站,因此两个网站都在工作,这让我怀疑我在VirtualHost中配置了错误,或者在我的域名注册商结束。
答案 0 :(得分:0)
我的问题是我在blog.example.com域之前有了example.com域名,这意味着所有内容都转到了example.com。订单很重要!