如何设置本地服务器,以便在本地计算机上访问类似www.my-dev-branch.com的内容时,它指向系统上的文件,例如: 'C:/wamp/www/www.my-dev-copy.com'
注意,我在Windows 7上使用WAMP
答案 0 :(得分:3)
通常这种操作是在C:\ WINDOWS \ SYSTEM32 \ DRIVERS \ ETC中操作主机文件
你添加这样的一行
127.0.0.1 www.my-dev-branch.com
请记住,在Win7中,此路径隐藏在普通视图之外 您需要直接在资源管理器窗口的地址栏中键入路径 当然需要管理员权限。
答案 1 :(得分: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.