简体   繁体   English

Apache多个本地虚拟主机

[英]Apache multiple local virtual host

I'm working on an Ubuntu 12.04 server with Apache and I'm trying to setup 2 virtual host. 我正在使用Apache的Ubuntu 12.04服务器上工作,并且试图设置2个虚拟主机。 The problem is I don't know how to setup the .conf files correctly so that I can hit both virtual host correctly from a remote machine... 问题是我不知道如何正确设置.conf文件,以便可以从远程计算机正确访问两个虚拟主机。

For example if the Ubuntu sever has an address of 192.168.1.3, and I'm using another machine, how can I access each virtual host with http://192.168.1.3/host1 and http://192.168.1.3/host2 ? 例如,如果Ubuntu服务器的地址为192.168.1.3,而我使用的是另一台计算机,如何使用http://192.168.1.3/host1http://192.168.1.3/host2访问每个虚拟主机?

right now in my /etc/apache2/sites-available folder I have the following 2 files 现在在我的/ etc / apache2 / sites-available文件夹中,我有以下2个文件

host1.conf host1.conf

<VirtualHost *:80>
ServerName 192.168.1.3/host1
ServerAlias host1
DocumentRoot /var/www/host1/
.....

host2.conf host2.conf

<VirtualHost *:80>
ServerName 192.168.1.3/host2
ServerAlias host2
DocumentRoot /var/www/host2/
.....

what is the correct configuration to make the virtual host work correctly when accessing from a remote machine? 从远程计算机访问虚拟主机时,正确的配置是什么?

The simplest way to achieve this is to assign host names to both your virtual hosts. 实现此目的的最简单方法是将主机名分配给两个虚拟主机。 Eg: host1.local.com & host2.local.com. 例如:host1.local.com&host2.local.com。 Then in your remote machine, open /etc/hosts (you will require sudo privileges) and add the following lines: 然后在您的远程计算机中,打开/ etc / hosts(您将需要sudo特权)并添加以下行:

192.168.1.3 host1.local.com
192.168.1.3 host2.local.com

Your virtual hosts config would be: 您的虚拟主机配置为:

<VirtualHost *:80>
ServerName host1.local.com

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

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