在具有相同IP和端口的Apache上托管多个站点

时间:2016-02-11 00:27:42

标签: ubuntu web apache2 virtualhost

尝试从同一个Ubuntu Apache框中托管多个站点。相同的IP和相同的端口。区别是主机头或域地址。我可以通过IIS轻松完成这项任务,但我想转移到Apache。

现在使用此代码,每次我使用这些网址进行测试。即使我尝试不同的URL,我也会指向第一个URL。 (我假设因为它是第一个80端口网站)。如果你在Ubuntu服务器的桌面上,一切都在本地工作,但如果你在本地桌面或互联网上没有。 (这些是我的实验室域名。)

我的www.conf文件位于/ etc / apache2 / sites-available中。在/ etc / apache2 / sites-enabled

中显示相同的conf文件
<VirtualHost *:80>
DocumentRoot /var/www/dizydiz

ServerName dizydiz.com
ServerAlias www.dizydiz.com

</VirtualHost>

###

<VirtualHost *:80>
DocumentRoot /var/www/dizydiz2

ServerName dizzydiz.com
ServerAlias www.dizzydiz.com

</VirtualHost>

###

<VirtualHost *:80>
DocumentRoot /var/www/squeakerkiller

ServerName squeakerkiller.com
ServerAlias www.squeakerkiller.com

</VirtualHost>

###

<VirtualHost *:80>
DocumentRoot /var/www/dizydiz_legacy1

ServerName old.dizydiz.com

</VirtualHost>

我在此Web框前面使用另一个Ubuntu框作为ProxyPass框。

<VirtualHost *:80>
     ServerName dizydiz.com
     ServerAlias www.dizydiz.com
     ServerAlias kb.dizydiz.com
     ServerAlias old.dizydiz.com
     ServerAlias squeakerkiller.com
     ServerAlias www.squeakerkiller.com
     ServerAlias dizzdiz.com
     ServerAlias www.dizzydiz.com

     ProxyPass / http://10.10.10.18/
     # ProxyPassReverse / http://10.10.10.18/

     # Uncomment the line below if your site uses SSL.
     #SSLProxyEngine On
</VirtualHost>

思想?

2 个答案:

答案 0 :(得分:0)

查看this superuser.com question上接受的答案我认为它可以解决您的问题。

如果该链接消失,请查看virtual hosts上的Apache页面。

答案 1 :(得分:0)

You need to activate the sites

Type the following commands to activate, replace "example" with your .conf name.

sudo a2ensite example.com.conf

then do

sudo service apache2 restart

You may get a error message saying: * Restarting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

This is fine, this will not effect your site.

Also follow this: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts