之前写过一篇Apache环境,单个端口运行多个网站的文章,使用不同域名映射到不同目录上。
《Apache中多个域名网站配置》
这次记录一下,Apache环境,如何开启多个端口服务,不同端口映射到不同的目录的文章,这次是运行在windows上,和Linux上大同小异。
环境:Windows上的XAMPP
主要配置两个文档,httpd-vhosts.conf和httpd.conf
配置httpd-vhosts.conf
文件位置在: D:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:/xampp/htdocs"
</VirtualHost>
<VirtualHost *:8059>
ServerName localhost
DocumentRoot "D:/xampp/htdocs/59"
</VirtualHost>
<VirtualHost *:8083>
ServerName localhost
DocumentRoot "D:/xampp/htdocs/83"
</VirtualHost>
上面8059和8083是增加的两个网站的端口,而83和59是网站本地目录
httpd.conf配置
文件位置在D:\xampp\apache\conf\httpd.conf
然后配置增加端口:8059和8083
# 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 80
Listen 8059
Listen 8083
DocumentRoot "D:/xampp/htdocs"
<Directory "D:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
注意:如果你的文件不是放在上面的默认目录下,请用Directory标签加上你的目录,这样用户才有权限去读取页面。
然后重新运行服务,就可以直接在本地测试网站,如下截图:
同时,80端口指向的根目录和8059端口指向59文件夹的网站,都能正常打开!