Apache 根据不同的端口 映射不同的站点
以前,在本地新建个项目,总是在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>