Apache的虚拟主机功能讲解及配置

本文详细介绍了Apache服务器的虚拟主机功能,包括基于IP地址、主机域名和端口号的配置方法。通过配置多个IP地址、主机域名映射和端口监听,实现多个网站在同一服务器上的服务。同时,文中给出了配置文件路径、测试步骤和访问测试效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

介绍及目的

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配置后结果如下
虚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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值