我将我的apache配置为设置了2个网站。我在apache2.conf中有以下内容
Include /opt/bitnami/apps/www.website1.com/conf/app.conf
Include /opt/bitnami/apps/www.website2.com/conf/app.conf
以下是2个网站的app.conf
WEBSITE1
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website1.com/htdocs
ServerName www.website1.com:80
ServerAlias website1.com
ErrorLog /opt/bitnami/apps/www.website1.com/log/error.log
CustomLog /opt/bitnami/apps/www.website1.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website1.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website1.com/htdocs
ServerName website1.uat.com:80
ServerAlias website1.uat.com
ErrorLog /opt/bitnami/apps/www.website1.com/log/error.log
CustomLog /opt/bitnami/apps/www.website1.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website1.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
网站2
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website2.com/htdocs
ServerName www.website2.com:80
ServerAlias www.website2.com
ErrorLog /opt/bitnami/apps/www.website2.com/log/error.log
CustomLog /opt/bitnami/apps/www.website2.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website2.com/htdocs">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website2.com/htdocs
ServerName website2.com:80
ServerAlias website2.com
ErrorLog /opt/bitnami/apps/www.website2.com/log/error.log
CustomLog /opt/bitnami/apps/www.website2.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website2.com/htdocs">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
我在本地测试这些,所以我有我的主机设置
xx.xxx.xx.xxx www.website1.com
xx.xxx.xx.xxx www.website2.com
当我访问www.website2.com时,会弹出apache2页面 当我访问www.website1.com时,会弹出apache2页面
当我访问www.website2.com/htdocs时,我看到了正确的网站,它确实有效。当我到www.website1.com/htdocs时,我看到website2。我不明白为什么我在这里看到网站2。
答案 0 :(得分:1)
我的第一个猜测是你应该从ServerName中删除端口:80并且还要更改
<VirtualHost *>
到
<VirtualHost *:80>
像这样:
<VirtualHost *:80>
DocumentRoot /opt/bitnami/apps/www.website1.com/htdocs
ServerName www.website1.com
...
答案 1 :(得分:-1)
正如prerik所说,使用“VirtualHost *:80”
此外,如果它是Apache HTTPD 2.2.x,当使用相同的ip:port方案存在多个虚拟主机时,它需要在配置中定义“一次”“NamedVirtualHosts *:80”,如果你不添加所有这些请求将登陆第一个定义的虚拟主机。