千家信息网

LAMP架构中Apache服务基于IP的虚拟主机配置的示例分析

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,这篇文章将为大家详细讲解有关LAMP架构中Apache服务基于IP的虚拟主机配置的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。基于IP的虚拟主机配置基于I
千家信息网最后更新 2026年10月31日LAMP架构中Apache服务基于IP的虚拟主机配置的示例分析

这篇文章将为大家详细讲解有关LAMP架构中Apache服务基于IP的虚拟主机配置的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

基于IP的虚拟主机配置

基于IP的虚拟主机----就是说每个虚拟主机使用一个独立的IP地址

服务器配置多块网卡实现,或者同一块网卡配置多个IP实现都可以

今天模拟的环境是同一网卡配置多个IP地址实现基于IP的虚拟主机配置

一:新增IP地址

[root@Centos ~]# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:0C:29:AA:CA:2B

inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:feaa:ca2b/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:2345 errors:0 dropped:0 overruns:0 frame:0

TX packets:694 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:224750 (219.4 KiB) TX bytes:92020 (89.8 KiB)

在eth0上新增一个IP地址用于测试使用

[root@Centos ~]# ifconfig eth0:20 192.168.1.20 netmask 255.255.255.0 up

[root@Centos ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:AA:CA:2B

inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:feaa:ca2b/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:2468 errors:0 dropped:0 overruns:0 frame:0

TX packets:767 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:235882 (230.3 KiB) TX bytes:100158 (97.8 KiB)

eth0:20 Link encap:Ethernet HWaddr 00:0C:29:AA:CA:2B

inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

二:联通性测试

在本地客户端主机上测试联通性

C:\Users\Administrator>ping 192.168.1.20

正在 Ping 192.168.1.20 具有 32 字节的数据:

来自 192.168.1.20 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.1.20 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.1.20 的回复: 字节=32 时间<1ms TTL=64

来自 192.168.1.20 的回复: 字节=32 时间<1ms TTL=64

192.168.1.20 的 Ping 统计信息:

数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),

往返行程的估计时间(以毫秒为单位):

最短 = 0ms,最长 = 0ms,平均 = 0ms

三:备份虚拟主机配置文件

提示:生产环境一定要养成良好的习惯

[root@Centos ~]# cd /application/apache/conf/extra/

[root@Centos extra]# cp httpd-vhosts.conf httpd-vhosts.conf.$(date +%F)

[root@Centos extra]# ls -ll

total 76

-rw-r--r--. 1 root root 2895 Sep 12 03:30 httpd-autoindex.conf

-rw-r--r--. 1 root root 1852 Sep 12 03:30 httpd-dav.conf

-rw-r--r--. 1 root root 2942 Sep 12 03:30 httpd-default.conf

-rw-r--r--. 1 root root 1119 Sep 12 03:30 httpd-info.conf

-rw-r--r--. 1 root root 5078 Sep 12 03:30 httpd-languages.conf

-rw-r--r--. 1 root root 1039 Sep 12 03:30 httpd-manual.conf

-rw-r--r--. 1 root root 4444 Sep 12 03:30 httpd-mpm.conf

-rw-r--r--. 1 root root 2243 Sep 12 03:30 httpd-multilang-errordoc.conf

-rw-r--r--. 1 root root 13506 Sep 12 03:30 httpd-ssl.conf

-rw-r--r--. 1 root root 694 Sep 12 03:30 httpd-userdir.conf

-rw-r--r--. 1 root root 1037 Sep 13 06:35 httpd-vhosts.conf

-rw-r--r--. 1 root root 1481 Sep 13 06:28 httpd-vhosts.conf.2016-09-13

-rw-r--r--. 1 root root 1037 Sep 15 02:04 httpd-vhosts.conf.2016-09-15

-rw-r--r--. 1 root root 3161 Sep 12 03:30 proxy-html.conf

四:配置虚拟主机配置文件

[root@Centos extra]# vi httpd-vhosts.conf

# Virtual Hosts

#

# Required modules: mod_log_config

# 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

#

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.

#

# 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 block.

#

192.168.1.20:80>

ServerAdmin admini@abc.com

DocumentRoot "/data/www/bbs"

ServerName 192.168.1.20

ServerAlias abc.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

上面的标记部分为修改的配置

[root@Centos extra]# ../../bin/apachectl graceful

httpd not running, trying to start

发现httpd服务并没有开机自启动

检查发现/etc/init.d/下没有httpd服务

[root@Centos extra]# cd /etc/init.d/

[root@Centos init.d]# ls

abrt-ccpp crond killall ntpd rpcgssd sshd

abrtd cups lvm2-lvmetad ntpdate rpcidmapd sssd

abrt-oops dnsmasq lvm2-monitor oddjobd rpcsvcgssd sysstat

acpid firstboot mdmonitor portreserve rsyslog udev-post

atd functions messagebus postfix sandbox wdaemon

auditd haldaemon netconsole psacct saslauthd winbind

autofs halt netfs quota_nld single wpa_supplicant

blk-availability ip6tables network rdisc smartd ypbind

bluetooth iptables NetworkManager restorecond snmpd

certmonger irqbalance nfs rngd snmptrapd

cpuspeed kdump nfslock rpcbind spice-vdagentd

[root@Centos init.d]# cp /application/apache/bin/apachectl ./httpd

不支持chkconfig

[root@Centos init.d]# chkconfig --add httpd

service httpd does not support chkconfig

因此编辑下面的文件,增加如下配置

[root@Centos init.d]# vi /etc/init.d/httpd

#!/bin/sh

#

#chkconfig:345 85 15

#description:Start and stop the Apache HTTP Server

[root@Centos init.d]# chkconfig --add httpd 加入启动

[root@Centos init.d]# chkconfig --list httpd 查看启动情况

httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off

[root@Centos init.d]# cd -

/application/apache/conf/extra

[root@Centos extra]# ../../bin/apachectl -t

Syntax OK

[root@Centos extra]# ../../bin/apachectl graceful

[root@Centos extra]# lsof -i tcp:80

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

httpd 2390 root 4u IPv6 16911 0t0 TCP *:http (LISTEN)

httpd 2531 daemon 4u IPv6 16911 0t0 TCP *:http (LISTEN)

httpd 2532 daemon 4u IPv6 16911 0t0 TCP *:http (LISTEN)

httpd 2533 daemon 4u IPv6 16911 0t0 TCP *:http (LISTEN)

[root@Centos extra]# ps -ef |grep httpd

root 2390 1 0 02:08 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful

daemon 2531 2390 0 02:22 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful

daemon 2532 2390 0 02:22 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful

daemon 2533 2390 0 02:22 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful

root 2623 1934 0 02:24 pts/1 00:00:00 grep httpd

五:测试访问

[root@Centos extra]# echo '192.168.1.20:80 this server is the server of bbs stie'>>/data/www/bbs/index.html

[root@Centos extra]# cat /data/www/bbs/index.html

welcome to bbs.abc.com

192.168.1.20:80 this server is the server of bbs stie

打开本地客户端浏览器


经测试表示之前的配置是正确的,同样的方法可以配置多个基于IP的虚拟主机

关于"LAMP架构中Apache服务基于IP的虚拟主机配置的示例分析"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

配置 主机 虚拟主机 服务 字节 时间 测试 地址 多个 文件 篇文章 网卡 架构 示例 分析 客户 客户端 数据 更多 环境 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网与科技发展 互联网 科技公司 深圳科技互联网 互联网 的科技创新 迪茉互联网科技 亿策互联网科技 互联网科技上市公司 四川狮子座互联网科技 中国互联网金融科技基金 上海电发互联网科技有限公司 创业天下互联网科技有限公司 互联网科技项目计划书材料类 昊天互联网科技有限公司 互联网科技革命什么开始 互联网金融科技名词解释 江苏互联网智能科技软件 广州有谷有贝互联网科技有限公司 宁波跨境商互联网科技有限公司 互联网科技接地气 平安好医生打造互联网科技医疗 湖南洣水互联网科技有限公司扣款 北京华百购互联网科技有限公司 全球顶尖互联网科技公司 黑科技闪耀互联网之光 企晟互联网信息科技有限公司 烟台灵鸽互联网科技有限公司 新氧科技和美国互联网有关系吗 第三届互联网大会安防黑科技 互联网科技企业文化 每日互联网科技新闻
0