简体   繁体   English

如何设置多个IP地址以指向Wamp服务器上的不同虚拟主机?

[英]How do I setup multiple ip addresses to point to different virtual hosts on wamp server?

I use WAMP server on my Windows machine. 我在Windows计算机上使用WAMP服务器。 I want to achieve the following setup: 我要实现以下设置:

1) I want to create multiple folders in my wamp's 'www' directory each representing a website. 1)我想在我的wamp的'www'目录中创建多个文件夹,每个文件夹代表一个网站。 2) Add multiple entries to my host file with different ip addresses, each pointing to one of the folders in the wamp's 'www' directory. 2)使用不同的IP地址将多个条目添加到我的主机文件中,每个条目都指向wamp的'www'目录中的文件夹之一。

So lets say, I create 3 folders in my wamp 'www' directory named - "site1", "site2", "site3" and add the following to my host file: 可以这么说,我在wamp的www目录中创建了3个文件夹,分别为“ site1”,“ site2”,“ site3”,并将以下内容添加到主机文件中:

127.0.0.1 site1.local 127.0.0.2 site2.local 127.0.0.3 site3.local 127.0.0.1 site1.local 127.0.0.2 site2.local 127.0.0.3 site3.local

And then I goto the url "site1.local", I can get to the folder "site1" and the same for other two as well. 然后转到URL“ site1.local”,我可以转到文件夹“ site1”,其他两个也一样。

My knowledge: I noticed that even if the host file is empty, going to any address in the format - "127.xx.xx.xx" where xx can be upto 99 and the last one not being 0 - will result in loading the default wamp page. 我的知识:我注意到,即使主机文件为空,也要转到格式为“ 127.xx.xx.xx”的任何地址,其中xx最多可以为99,最后一个不为0,这将导致加载默认的网页页面。

I know about setting virtual host servers in wamp through apache and addressing them to different directories. 我知道有关通过apache设置虚拟主机服务器并将其寻址到不同目录的知识。

My difficulty: I tried many different ways but any address would only straight away point to the default directory that I set in apache as the main host. 我的困难:我尝试了许多不同的方法,但是任何地址都只会立即指向我在apache中设置为主主机的默认目录。 I think the host file is meant to be used to point all the addresses to the same point no matter what address we add to it. 我认为,无论我们添加到哪个地址,主机文件都应用于将所有地址指向同一点。 (But I'm not sure...) (但我不确定...)

Please help me achieve the aforesaid setup. 请帮助我实现上述设置。

Can I suggest that you try Virtual Hosts again. 我可以建议您再次尝试虚拟主机。 Here is a tutorial on how to do it in WAMPServer. 这是有关如何在WAMPServer中执行此操作的教程。

WAMPServer forum - HOWTO Create Virtual hosts WAMPServer论坛-HOWTO创建虚拟主机

They should do exactly what you want but without the need to use different ip addresses. 他们应该完全按照您想要的方式工作,而无需使用其他IP地址。 When setup correctly all you need to enter in the browser address bar is you desirecd site domain name ie site2.dev and apache will switch you to the correct document root and the site will function as it is were a single site on Apache. 正确设置后,您需要在浏览器地址栏中输入您想要的站点域名,即site2.dev和apache将您切换到正确的文档根目录,并且该站点将像在Apache上的单个站点一样正常运行。

you can add below configuration in your virtual host file that is located in " C:/wamp/bin/Apache/#.#.#/conf/extra/httpd-vhosts.conf " . 您可以在虚拟主机文件“ C:/ wamp / bin / Apache /#.#.#/ conf / extra / httpd-vhosts.conf ”中添加以下配置。 If you want create multiple host you can replicate below configuration and give the appropriate project directory path and and your virtual host name. 如果要创建多个主机,则可以复制以下配置,并提供适当的项目目录路径和虚拟主机名。

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "c:/wamp/www/phpclicks"
ServerName phpclicks.com
ServerAlias www.phpclicks.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
  <Directory "/">
        Deny from all
        Allow from 127.0.0.1 localhost ::1
    </Directory>
</VirtualHost>

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

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