当前位置:Gxlcms > PHP教程 > Apache虚拟主机的配置

Apache虚拟主机的配置

时间:2021-07-01 10:21:17 帮助过:5人阅读

Apache虚拟主机的配置
* 条件:在http.conf 中将 httpd-vhosts.conf包含进来
* # Virtual hosts
Include conf/extra/httpd-vhosts.conf
* 在 httpd-vhost.conf中配置
* (1)基于IP的虚拟主机
* 修改hosts文件,添加3个域名与之对应
* 192.168.1.11 www.test1.com
* 192.168.1.12 www.test2.com
* 192.168.1.13 www.test3.com
* 建立虚拟主机存放文件的根目录,如
* www/test1/1.html
* www/test2/2.html
* www/test3/3.html
* 在httpd-vhosts.conf进行如下配置
*
* ServerName www.test1.com
* DocumentRoot "www/test1"
*
* Options Indexs FollowSysLinks
* AllowOverride None
* Order allow deny
* allow from all
* DirectoryIndex index.html index.htm index.php
*

*

*
*

  ServerName www.test2.com
DocumentRoot /www/test2/

 Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All


*
*

ServerName www.test3.com
DocumentRoot /www/test3/

    Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
  Allow From All
 


*
* (2)基于主机名
* 设置域名映射同一个主机
* 192.168.1.10 www.test1.com
* 192.168.1.10 www.test2.com
* 192.168.1.10 www.test3.com
* 设置存放网页的根目录
* www/test1/1.html
* www/test2/2.html
* www/test3/3.html
* 在使用基于域名的虚拟主机时,必须指定服务器的IP地址和可能的访问端口来使主机接受请求,可以
* 使用NameVirtualHost指令来配置,如果服务器上所有的IP都会用到,则可以使用*来表示,
* 在NameVirtualHost指定的ip并不会让服务器监听这个IP
* 然后配置
* 如果在现有的WEB服务器上配置虚拟主机,则必须为现存的虚拟主机也配置,其中
* ServerName 和 DocumentRoot包含的内容应该与全局的内容一致,且要放在配置文件的最前面,
* 作为默认主机的配置
* NameVirtualHost *:80
*
* ServerName www.test1.com
* DocumentRoot "www/test2"
*
* Options Indexs FollowSymLinks
* AllowOverride None
* Order allow,deny
* allow from all
*

*

* *
* ServerName www.test2.com
* DocumentRoot "www/test2"
*
* Options Indexs FollowSymLinks
* AllowOverride None
* Order allow,deny
* allow from all
*

*

* *
* ServerName www.test3.com
* DocumentRoot "www/test3"
*
* Options Indexs FollowSymLinks
* AllowOverride None
* Order allow,deny
* allow from all
*

*

*
* (3)基于端口
* 修改httpd.conf
* 设置为 Listen 8001
* Listen 8002
* 修改虚拟主机配置文件 httpd-vhosts.conf
*
* ServerName www.test1.com
* DocumentRoot "www/test1"
*

* *
* ServerName www.test2.com
* DocumentRoot "www/test2"
*

以上就介绍了Apache虚拟主机的配置,包括了Apache方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行