Linux中Apache Web服务器配置

时间:2024-05-19 22:34:19

一、 实验内容

配置Web服务器,可以从客户端访问服务器,打开网页。

二、 服务器端设置

1、 配置DNS服务器,要求能够解析域名。
如果还没配置DNS,请移步到此》》》戳我
2、 配置Web 服务器

三、操作方法

(1)、

	[[email protected] named]# cd /run/media/root/RHEL-7.2\ Server.x86_64/Packages/  //虚拟机选择
----------------------------------------------------------------------------------------------------------------------------------
    [[email protected] named]# cd /mnt/RHEL-7.2\ Server.x86_64/Packages/   //云平台选择

(2)、查询所需要安装的包名

[[email protected] Packages]# ls httpd*

httpd-2.4.6-40.el7.x86_64.rpm
httpd-devel-2.4.6-40.el7.x86_64.rpm
httpd-manual-2.4.6-40.el7.noarch.rpm
httpd-tools-2.4.6-40.el7.x86_64.rpm
安装黄色标记的三个程序包。

(此步奏不需要执行,警示作用)
[[email protected] Packages]# rpm -ivh httpd-2.4.6-40.el7.x86_64.rpm
警告:httpd-2.4.6-40.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, ** ID fd431d51: NOKEY
错误:依赖检测失败:
/etc/mime.types 被 httpd-2.4.6-40.el7.x86_64 需要
httpd-tools = 2.4.6-40.el7 被 httpd-2.4.6-40.el7.x86_64 需要
libapr-1.so.0()(64bit) 被 httpd-2.4.6-40.el7.x86_64 需要
libaprutil-1.so.0()(64bit) 被 httpd-2.4.6-40.el7.x86_64 需要
可以看到缺少mime.types文件。缺少http-tools文件,apr和apr-utils文件,一个一个安装所需软件包。首先安装mailcap软件包添加mime.types文件。

(3)

[[email protected] Packages]# ls mailcap*
mailcap-2.1.41-2.el7.noarch.rpm
[[email protected] Packages]# rpm -ivh mailcap-2.1.41-2.el7.noarch.rpm 

(4)安装apr和apr-util软件,型号为x86_64。

[[email protected] Packages]# ls apr*
apr-1.4.8-3.el7.i686.rpm          apr-util-1.5.2-6.el7.i686.rpm
apr-1.4.8-3.el7.x86_64.rpm        apr-util-1.5.2-6.el7.x86_64.rpm
apr-devel-1.4.8-3.el7.i686.rpm    apr-util-devel-1.5.2-6.el7.i686.rpm
apr-devel-1.4.8-3.el7.x86_64.rpm  apr-util-devel-1.5.2-6.el7.x86_64.rpm
[[email protected] Packages]# rpm -ivh apr-1.4.8-3.el7.x86_64.rpm 
[[email protected] Packages]# rpm -ivh apr-util-1.5.2-6.el7.x86_64.rpm 
[[email protected] Packages]# rpm -ivh httpd-tools-2.4.6-40.el7.x86_64.rpm 

(5)安装其他软件包

[[email protected] Packages]# rpm -ivh httpd-2.4.6-40.el7.x86_64.rpm
[[email protected]```alhost Packages]# rpm -ivh httpd-manual-2.4.6-40.el7.noarch.rpm 

(6)进入配置文件开始配置
[[email protected] Packages]# vi /etc/httpd/conf/httpd.confLinux中Apache Web服务器配置
(7)

再次使用apachectl configtest命令查看,检查出错,如果缺少MPM模块
[[email protected] Packages]# apachectl configtest
AH00534: httpd: Configuration error: No MPM loaded.

解决方案:进入配置文件修改最后两句

[[email protected] Packages]# vi /etc/httpd/conf/httpd.conf

修改的内容:
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
Include conf.modules.d/*.conf

(8)然后打开日志。再次检查,如果检查通过立即开启httpd服务

[[email protected] Packages]# apachectl configtest
[Mon Apr 09 23:25:12.255702 2018] [so:warn] [pid 13061] AH01574: module mpm_prefork_module is already loaded, skipping
Syntax OK

//开启服务

[[email protected] Packages]# systemctl start httpd.service

(9)如果第八步还不能开启服务

打开日志查看下错误信息,缺少文件
[[email protected] logs]# cat /etc/httpd/logs/error_log
[Tue Apr 10 12:29:49.557017 2018]
[core:notice] [pid 19247] SELinux policy enabled; httpd running as
context system_u:system_r:httpd_t:s0 [Tue Apr 10 12:29:49.557123 2018]
[mime:error] [pid 19247] (2)No such file or directory: AH01597: could
not open mime types config file /etc/httpd/conf/mime.types. AH00016:
Configuration Failed

所以上述错误需要把文件复制到/etc/httpd/conf/mime.types.

[[email protected] ~]# cp /etc/mime.types  /etc/httpd/conf/
[[email protected] ~]# cd /etc/httpd/conf/ 
[[email protected] conf]# ls 
httpd.conf  magic  mime.types  
[[email protected] conf]#

(10)再次启动httpd,没有问题,可以启动了!

[[email protected] conf]# systemctl start httpd.service
[[email protected] conf]#

(11)、将网页保存到var/www/html/目录中

[[email protected] conf]# echo "这里可以输入你想要的内容"  >/var/www/html/index.html

(12)
开大浏览器输入你的域名,出现(11)中你输入的内容,成功!!!!