简体   繁体   English

Apache2上的多个网站

[英]Multiple Websites on Apache2

I have my apache configured to have 2 websites setup. 我的apache配置为设置2个网站。 I have the following in my apache2.conf 我的apache2.conf中包含以下内容

Include /opt/bitnami/apps/www.website1.com/conf/app.conf
Include /opt/bitnami/apps/www.website2.com/conf/app.conf

Here are the app.conf for the 2 websites 这是两个网站的app.conf

Website1 网站1

<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>

Website 2 网站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>

Im testing these locally so i have my host setup below 我在本地测试这些,所以我在下面设置了主机

xx.xxx.xx.xxx www.website1.com
xx.xxx.xx.xxx www.website2.com

When i go to www.website2.com, apache2 page pops up When i go to www.website1.com, apache2 page pops up 当我去www.website2.com时,会弹出apache2页面当我去www.website1.com时,会弹出apache2页面

When i go to www.website2.com/htdocs, i see the correct website and it works. 当我访问www.website2.com/htdocs时,我会看到正确的网站,并且可以正常工作。 When i got to www.website1.com/htdocs, i see website2. 当我到达www.website1.com/htdocs时,我看到了website2。 I dont understand why i am seeing website 2 here. 我不明白为什么我在这里看到网站2。

My first guess would be that you should remove the port :80 from ServerName and also change 我的第一个猜测是,您应该从ServerName删除端口:80,然后更改

<VirtualHost *> 

to

<VirtualHost *:80>

Like so: 像这样:

<VirtualHost *:80>
DocumentRoot /opt/bitnami/apps/www.website1.com/htdocs
ServerName www.website1.com
...

As prerik says use "VirtualHost *:80" 如prerik所说,使用“ VirtualHost *:80”

Also if it is Apache HTTPD 2.2.x, it needs "NamedVirtualHosts *:80" defined "once" in the config when several virtualhosts are present using the same ip:port scheme, if you don't add this all your requests will land in the first defined virtualhost. 另外,如果它是Apache HTTPD 2.2.x,则当使用相同的ip:port方案存在多个虚拟主机时,需要在配置中将“ NamedVirtualHosts *:80”定义为“ once”,如果不添加,则所有请求都将落入在第一个定义的虚拟主机中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM