介绍及目的
Apache 为web 服务器之一,能够为企业提供提供web服务。apache 是跨平台的、模块化的服务器。
apache 一般作为静态网站服务器,但通过集成第三方模块也能支持python、java 等开发的动态网站。
它有诸多特性, 其中虚拟主机功能是一个重要的特性,也是本节讲解内容。
虚拟主机功能能够提供多个网站服务的能力。
配置环境
Cenos v6
apache 2.2.15
配置文件
/etc/httpd
/etc/httpd/httpd.conf
/etc/httpd/logs/access_log
/etc/httpd/logs/error_log
配置过程
基于IP地址
配置多个IP地址,本次使用虚IP 技术提供多IP地址
ifconfig bond:1 172.16.34.140 netmask 255.255.255.0 up
ifconfig bond:2 172.16.34.140 netmask 255.255.255.0 up
虚IP配置后结果如下
配置https.conf 中监听的端口号
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to 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 (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 80
配置VirtualHost,使用提前配置号的虚实IP作为多IP地址
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
###ServerName Method###
<VirtualHost 172.16.34.130>
ServerAdmin root@localhost
DocumentRoot /var/www/html/wb1
ServerName test.wb1.com
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
<VirtualHost 172.16.34.140>
ServerAdmin root@localhost
DocumentRoot /var/www/html/wb2
ServerName test.wb2.com
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost