2

如何设置本地服务器,以便如果您在本地计算机上访问类似 www.my-dev-branch.com 的内容,它会指向您系统上的文件,例如 'c:/wamp/www/www.my-dev -copy.com'

注意,我在使用 WAMP 的 Windows 7 上

4

2 回答 2

3

通常这种事情是通过操作C:\WINDOWS\SYSTEM32\DRIVERS\ETC 中的hosts文件来完成的

你像这样添加一行

127.0.0.1       www.my-dev-branch.com 

请记住,在 Win7 中,这条路径在正常视图中是隐藏的。
您需要直接在资源管理器窗口的地址栏中键入路径。
当然需要管理员权限

于 2012-06-01T21:05:03.293 回答
0

我在下面找到了我想要的东西:

http://www.infotales.com/seting-up-local-domains-windows-apache-wamp/

Recently had to setup local domains for my php projects. Normally I use http://localhost/project_directory urls for normal project, but for a new project I had to setup few local domains. For existing projects I still need localhost (127.0.0.1) available along local domains like project.localhost.com. Setting up local domains and virtual hosts is easy and I found it worth sharing.
I am using Windows Vista Business with WampServer Version 2.0 installed. This method should also work for standalone apache installation.
First we need to add host entry in windows host. To do this, open file
C:\Windows\System32\drivers\etc\hosts
in some text editor, by using Open With menu from right click.
Note that C: represent your drive where windows is installed, in most cases it will be C: but it can be different.
You will see content smiler to
# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
::1 localhost
Now add this line
127.0.0.1 project.localhost.com

at the end. Here you can add any custom domain like projectname.local etc.
The line added tells windows to resolve to local IP when ever this domain name is requested by browser etc. Be sure not to add any live existing domains as they will be resolved to localhost instead of live host.
Now we need to add virtual host entry in Apache server so we can server our project files. For this apache config file which in this case is
C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf
. Open the file with text editor and find following lines
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
The second line tells conf file to include another configuration file which contains virtual host configurations. The line is commented by default so we have to enable it.
Now remove
#
sign from start of the second line and save file, so the line will look
Include conf/extra/httpd-vhosts.conf
.
Now open file
C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
to add virtual host entries.
Add following lines to the file.
<VirtualHost 127.0.0.1>
DocumentRoot "C:/websites/myproject/public/"
ServerName project.localhost.com
ServerAlias project.localhost.com
</VirtualHost>
You may also need to remove any example virtual hosts.
After this restart your apache and test the url http://project.localhost.com/ in browser.
于 2012-06-17T03:35:06.850 回答