apache可以配置哪些虚拟机
1. 如何配置 Apache 的虚拟主机
1、基于ip地址的虚拟主机
复制代码代码如下:
Listen 80
<VirtualHost 172.20.30.40>
DocumentRoot /home/httpd/html1
ServerName www.ok1.com
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_log combined
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /home/httpd/html2
ServerName www.ok2.com
ErrorLog /usr/local/apache/logs/error2_log
CustomLog /usr/local/apache/logs/access2_log combined
</VirtualHost>
2、基于IP 和多端口的虚拟主机配置
复制代码代码如下:
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>
3、单个IP 地址的服务器上基于域名的虚拟主机配置
复制代码代码如下:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>
如果您感觉上面的文章还不够详细可以看下下面的文章:
实验目标:在apache实现基于域名的虚拟主机
实验用的XAMPP版本为1.7.7,内含apache版本为2.2.21
实验前准备:
1. 为了测试不同的域名,在Windows/System32/drivers/etc/下觅得hosts文件,在其中添加实验用的域名若干,如 -
复制代码代码如下:
127.0.0.1 test1.net
127.0.0.1 test2.net
如此,则在浏览器中输入该俩域名时,Windows将其解析为127.0.0.1本地地址。即,在浏览器中访问localhost, test1.net, test2.net均可访问XAMPP的欢迎页。
2. 在apache目录下建立目录,以放置您不同的网站。为保护XAMPP原有的htdocs中的欢迎页内容,实验另外建立了与htdocs平级的htdocs1目录,在其下建立了test1.net, test2.net两个子目录用以放置实验用的网站。如下 -
apache/htdocs1/test1.net - 放置test1.net网站内容
apache/htdocs1/test2.net - 放置test2.net网站内容
在这两个目录中各新建hello world一网页 index.html,内容 -
复制代码代码如下:
<HTML>
<HEAD></HEAD>
<BODY>
<H1>hello~, 这是[对应的网站名,用以区别].net</H1></BODY>
</HTML>
实验步骤:
1. 找到apache/conf/httpd.conf, 将其中的
ServerAdmin
ServerName
DocumentRoot
注释掉。
2. 在httpd.conf中,找到行
Include "conf/extra/httpd-vhosts.conf"
如被注释则解注。该文件记载了虚拟主机的参数。[以前虚拟主机参数是直接填写在httpd.conf中的,为了更好地组织文件,将其分离出去,类似于某些编程语言一样。因此httpd.conf中include它,即相当于把它的内容填在了httpd.conf中。]
3. 这个httpd-vhosts.conf文件格式基本如下 -
复制代码代码如下:
#blah-blah
NameVirtualHost *:80
#blah-blah
#blah-blah
<VirtualHost *:80>
ServerAdmin XXXXXXXX
DocumentRoot "XXXXXXXX"
ServerName XXXXXXX
ServerAlias XXXXXX
ErrorLog "logs/XXXXXX-error.log"
CustomLog "logs/XXXXXXX-error.log" combined
</VirtualHost>
需要修改的,就是<VirtualHost>中的参数了。这个可以参见apache官方文档。根据实验域名,可以增加两个<VirtualHost>:
复制代码代码如下:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs1/test1.net"
ServerName test1.net
ServerAlias www.test1.net
ErrorLog "logs/test1-error.log"
CustomLog "logs/test1-access.log" combined
<Directory "C:/xampp/htdocs1/test1.net">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs1/test2.net"
ServerName test2.net
ServerAlias www.test2.net
ErrorLog "logs/test1-error.log"
CustomLog "logs/test1-access.log" combined
<Directory "C:/xampp/htdocs1/test2.net">
order allow,deny
allow from all
</Directory>
</VirtualHost>
注意,如果不在各VirtualHost中定义Directory的可访问性,你将遇到的是Access Forbidden!就连原来的localhost也是。
4. 由于之前注释掉了httpd.conf中的ServerName, DocumentRoot等,为了仍然能以localhost访问原XAMPP欢迎页,就在增加一个VirtualHost,如下 -
复制代码代码如下:
<VirtualHost *:80>
ServerAdmin adm@localhost
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined
<Directory "C:/xampp/htdocs">
order allow,deny
allow from all
</Directory>
</VirtualHost>
为了避免出错,把它放置在第一个Virtualhost位置。
至此,apache基于域名的虚拟主机配置完成。可以通过http://localhost访问XAMPP欢迎页,通过http://test1.net和http://test2.net访问各自的主页。
#
# 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.
#
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs"
ServerName localhost
ServerAlias www.sky.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined
<Directory "E:/sky/apache2/htdocs">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/project1"
ServerName project1.com
ServerAlias www.project1.com
ErrorLog "logs/project1-error.log"
CustomLog "logs/project1-access.log" combined
<Directory "E:/sky/apache2/htdocs/project1">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/zendTest/public"
ServerName zendTest.com
ServerAlias www.zendTest.com
DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/testRewrite"
ServerName testRewrite.com
ServerAlias www.testRewrite.com
# DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "E:/sky/apache2/htdocs/test"
ServerName test.com
ServerAlias www.test.com
ErrorLog "logs/zendTest-error.log"
CustomLog "logs/zendTest-access.log" combined
<Directory "E:/sky/apache2/htdocs/test">
order allow,deny
allow from all
</Directory>
</VirtualHost>
2. 如何进行Apache虚拟机设置
Apache虚拟机设置有两种方法: 基于主机名的虚拟主机(一个IP地址,多个网站) 基于IP地址的虚拟主机(每个站点拥有一个的独立IP地址) 可能很多人没有多个静态ip,也没有多个域名,也没有线上的服务器。我也没有。不过我们还是可以在本机实现Apache虚拟机设置的。下面我们要用到的ip是 127.0.0.1, 127.0.0.2。域名是localhost, localhost2, localhost3打开/etc/hosts在后面添加127.0.0.1 localhost2 127.0.0.2 localhost3windows的系统是修改 C:\WINDOWS\system32\drivers\etc\hosts 文件这一步需要重启一下机器。先重启了再进行下边的操作。重启后 localhost2和localhost3就可以指向各住的ip了。打开apache配置文件。一般是在 /etc/httpd/conf/httpd.conf 或者你指定的目录。windows的系统是在apache安装目录的conf文件夹里 在最后添加NameVirtualHost 127.0.0.1:80ServerAdmin [email protected] DocumentRoot /home/webroot/website1 ServerName localhostServerAdmin [email protected] DocumentRoot /home/webroot/website2 ServerName localhost2ServerAdmin [email protected] ServerName localhost3其中DocumentRoot要改成和自己机子相符的路径。然后务必重启apache才可以生效。 service httpd restart 重启apache。然后用localhost localhost2 和 localhost3 就可以访问各住的目录了。其中NameVirtualHost 127.0.0.1:80 是需要的,否则会出现这样的警告提示:VirtualHost 127.0.0.1:80 overlaps with VirtualHost 127.0.0.1:80, the first has precedence, perhaps you need a NameVirtualHost directive 如果需要一个虚拟机绑定多个域名,则可以在别名 ServerAlias 后面全部列出来。还可以通过 php_admin_value open_basedir 限制各自虚拟机可操作文件的目录。同时可以通过 ErrorDocument 404 设置404错误页面的位置。其他配置就不多说了,可以参考apache手册。至此,Apache虚拟机设置就完成了。
3. 用户apache 配置服务器的虚拟主机,有几种不同虚拟技术可以完成
apache是开源的web服务软件之一,也是现在开源系统比如centos上安装web服务常见软件;
虚拟主机是提供网站服务的集成环境,比如:linux Apache+php+mysq LAMP
就是常说的建站开通的虚拟空间;
所以
Apache服务器只是虚拟空间的一种架构.
4. 在虚拟机上如何配置apache
1、安装apache:make,make install。
2、把虚拟机配置成桥接模式。
3、把虚拟机防火墙关掉。
4、把虚拟机和客户机设置成同一个网段内。
5、启动apache:/usr/local/apache2/bin/apachectl start
6、配置apache 的conf目录下面的http.conf:
ServerName: 主机地址和端口
DocumentRoot:默认文档。
7、访问apache,成功!
如果想访问svn,那么加上如下东西:
打开apache的httpd.conf文件,应该在/etc/httpd/conf/httpd.conf下
将231,232行改为User apache Group apache ,如果已经改过来就不用改了。
在最后添加(注意:要在英文状态下输入,并且#后的注释内容不要写的配置文件里,否则apache启动不了)DAV svnAuthType Basic
# SVNPath /usr/linux/xiu #单库时需要这么写,xiu为库名。
SVNParentPath /usr/linux #库路径(多库),根据实际情况而定。
AuthName "repos-project"
AuthUserFile "/etc/httpd/passwd" #存放用户名及密码的文件路径。