以前,在本地新建個項目,總是在Apache的htdocs目錄下新建個項目目錄,今年弄了個別人寫好的網站源碼,因為該系統的作者假定網站是放在根目錄的,放在二級目錄下會出錯。所以無奈,只能想辦法,根據端口映射到一個新的站點。
在網上查了下資料,以下是我的修改過程:
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
首先,在Apache的配置文件httpd.conf中,找到上面的兩條語句,將第二行前面的注釋符‘#’去掉,改成:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
然后,打開conf\extra文件夾,打開httpd-vhosts.conf文件,這個是一個模板文件,稍做修改即可,以下是我改后的文件內容:
# # Virtual Hosts # # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.2/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # Use name-based virtual hosting. # #NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. #
Listen 8090 <VirtualHost *:8090> ServerAdmin webmaster@dummy-host.localhost DocumentRoot "D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/wanjinv3" ServerName localhost:8090 # ServerAlias www.dummy-host.localhost ErrorLog "logs/dummy-host.localhost-error.log" CustomLog "logs/dummy-host.localhost-access.log" common <Directory "D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/wanjinv3"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> </VirtualHost>