php配置虚拟主机(一个php支持多个端口-站点访问)

在实际开发中,为了实现多个项目通过根目录访问,可以通过配置Apache虚拟主机来实现。步骤包括:编辑httpd.conf增加监听端口,如8081和8082,并在httpd-vhosts.conf文件中定义虚拟主机目录,分别指定不同项目路径,允许所有访问。
摘要由CSDN通过智能技术生成

实际开发中一个来发会有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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值