mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4mobile wallpaper 5mobile wallpaper 6mobile wallpaper 7mobile wallpaper 8mobile wallpaper 9mobile wallpaper 10mobile wallpaper 11mobile wallpaper 12mobile wallpaper 13mobile wallpaper 14mobile wallpaper 15mobile wallpaper 16
318 字
1 分钟
Apache服务器安装与配置
2025-11-18

步骤一:配置Apache服务器#

1. 配置网络#

服务器启动DHCP服务器,为客户机分配IP地址:

setenforce 0
systemctl stop firewalld
systemctl start dhcpd

(客户机)

p1

2. 安装Apache软件包(需要先配置yum本地源)#

yum install httpd -y

3. 服务器本机测试#

打开firefox浏览器(没有的话自己用 yum 安装):

yum install firefox
systemctl start httpd

然后打开firefox浏览器:

p2

在地址栏输入服务器的IP地址进行测试,比如 192.241.42.3

p4

出现Apache的默认页面,说明安装成功。

4. 客户机测试#

在客户机(Windows 或 Linux)中打开浏览器,输入服务器的IP地址 192.241.42.3

p5

步骤二:管理Apache服务器#

1. 建立虚拟目录#

/var/www/html 目录下创建 reading 文件夹,并创建 index.html

mkdir /var/www/html/reading
echo "hello reading!" > /var/www/html/reading/index.html

在服务器浏览器输入 http://192.241.42.3/reading 进行测试:

p6

2. 建立虚拟主机#

(1) 基于IP地址的虚拟主机#

/etc/httpd/conf.d 目录下创建 vhost.conf

vi /etc/httpd/conf.d/vhost.conf

输入以下内容:

<VirtualHost 192.241.42.3:80>
DocumentRoot /var/www/html/ip3
</VirtualHost>
<VirtualHost 192.241.42.4:80>
DocumentRoot /var/www/html/ip4
</VirtualHost>

创建对应目录和文件:

mkdir /var/www/html/ip3
mkdir /var/www/html/ip4
echo "IP 192.241.42.3" > /var/www/html/ip3/index.html
echo "IP 192.241.42.4" > /var/www/html/ip4/index.html

注意: 服务器需要有两个IP地址。可以使用 ifconfigip addr 添加子接口:

ifconfig ens33:1 192.241.42.4 netmask 255.255.255.0

重启服务测试:

systemctl restart httpd
p7

(2) 基于主机名的虚拟主机#

修改 /etc/httpd/conf.d/vhost.conf

<VirtualHost 192.241.42.3:80>
ServerName www.mypt.com
DocumentRoot /var/www/html/mypt
</VirtualHost>
<VirtualHost 192.241.42.3:80>
ServerName www.reading.com
DocumentRoot /var/www/html/reading
</VirtualHost>

创建目录和文件,并配置 /etc/hosts(或 DNS 服务):

echo "192.241.42.3 www.mypt.com" >> /etc/hosts
echo "192.241.42.3 www.reading.com" >> /etc/hosts

测试:

p8 p9
分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Apache服务器安装与配置
https://mizuki.ipox.cn/posts/zh-cn/apache-config/
作者
槿鸢
发布于
2025-11-18
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

目录

封面
Sample Song
Sample Artist
封面
Sample Song
Sample Artist
0:00 / 0:00