实际开发中一个来发会有N多个项目,需求是要用根目录地址访问站点而不是通过站点后添加文件夹方式,最简单的做法就是配置虚拟主机了
打开Apache的配置文件httpd.conf
在Listen 80
下面添加多个监听端口如
Listen 8081
Listen 8082
这样就增加了8011和8088端口的监听
然后在conf\extra\httpd-vhosts.conf 设置虚拟主机目录,只需在尾部添加即可,如:
<VirtualHost *:8081>
ServerAdmin webmaster@dummy-host.localhost
DocumentRoot "D:\HX_pr\A_Web\ManagerWEB\htdocsNewPage"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" common
<Directory "D:\HX_pr\A_Web\ManagerWEB\htdocsNewPage">
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8082>
ServerAdmin webmaster@dummy-host2.localhost
DocumentRoot "D:\HX_pr\A_Web\ManagerWEB\htdocsNewClear"
ServerName localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" common
<Directory "D:\HX_pr\A_Web\ManagerWEB\htdocsNewClear">
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
httpd.conf配置
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/access_log"
# with ServerRoot set to "/usr/local/apache2" will be interpreted by the
# server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log"
# will be interpreted as '/logs/access_log'.
#
# NOTE: Where filenames are specified, you must use forward slashes
# instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
# If a drive letter is omitted, the drive on which httpd.exe is located
# will be used by default. It is recommended that you always supply
# an explicit drive letter in absolute paths to avoid confusion.
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used. If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
#ServerTokens Prod
#ServerSignature Off
define ListenPort "80"
define ServerRoot "D:/HX_pr/A_Web/ManagerWEB"
ServerRoot "${ServerRoot}"
#
# Mutex: Allows you to set the mutex mechanism and mutex file directory
# for individual mutexes, or change the global defaults
#
# Uncomment and change the directory if mutexes are file-based and the default
# mutex file directory is not on a local disk or is not appropriate for some
# other reason.
#
# Mutex default:logs
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen ${ListenPort}
Listen 8081
Listen 8082
#
# Dynamic Shared Obje