CentOS 8 的Apache服务器配置与管理

目录

安装、启动与停止Apache服务

Apache配置实例


安装、启动与停止Apache服务

(1)使用dnf命令安装httpd服务(光盘挂载、yum源的制作请参考前面相关内容)。

[root@Server01 ~]# mount  /dev/cdrom  /media
[root@Server01 ~]# dnf  clean  all    //安装前先清除缓存
[root@Server01 ~]# dnf  install  bind  httpd  -y

2.重新启动和停止的命令分别是restart和stop。

[root@Server01 ~]# systemctl  start  httpd
[root@Server01 ~]# systemctl  stop  httpd

2.2  让防火墙放行,并设置SELinux为允许
1.使用防火墙命令,放行http服务。

[root@Server01 ~]# firewall-cmd  --permanent  --add-service=http
[root@Server01 ~]# firewall-cmd  --reload

2.更改当前的SELinux值,后面可以跟Enforcing、Permissive或者1、0。

[root@Server01 ~]# setenforce  0或setenforce  Permissive

注意:

利用setenforce设置SELinux值,重启系统后失效,如果再次使用httpd,则仍需重新设置SELinux,否则客户端无法访问Web服务器。如果想长期有效,请修改/etc/sysconfig/selinux文件,按需要赋予SELINUX相应的值(Enforcing|Permissive,或者“0”|“1”)。

2.3  测试httpd服务。
1.安装Apache服务器后启动它,并设置开机自动加载。

[root@Server01 ~]# systemctl  start  httpd
[root@Server01 ~]# systemctl  enable  httpd
[root@Server01 ~]# firefox http://127.0.0.1

2.测试成功界面。
如果看到图所示信息,表示Apache服务器已安装成功。也可以在Applications菜单中直接启动firefox,然后在地址栏输入http://127.0.0.1,测试是否成功安装。
 


Apache配置实例

项目需求
1.将网站文档的根目录修改为/home/wwwroot;

2.将首页文件修改为myweb.html;

3.网页内容设计为“The  Web's  DocumentRoot  Test ”。

第1步:新建网站根目录/home/www,创建首页文件myweb.html。

[root@Server01 ~]# mkdir  /home/www
[root@Server01 ~]#echo  "The  Web's  DocumentRoot  Test "   >  /home/www/myweb.html

第2步:在Server01上,先备份主配置文件,然后打开httpd服务程序的主配置文件,将约第122行用于定义网站数据保存路径的参数DocumentRoot修改为/home/www,同时将约第127行用于定义目录权限的参数Directory后面的路径也修改为/home/www,将第167行修改为DirectoryIndex myweb.html index.html。配置文件修改完毕即可保存并退出。
 

[root@Server01 ~]# vim /etc/httpd/conf/httpd.conf 
……
122 DocumentRoot   "/home/www"
……
127 <Directory  "/home/www">
……
131 </Directory>
……
167 DirectoryIndex  index.html  myweb.html

第3步:防火墙放行http协议,设置SELinux为允许(之前设置过,可忽略),重启httpd服务。
 

[root@Server01 ~]# firewall-cmd  --permanent  --add-service=http
[root@Server01 ~]# firewall-cmd  --reload
[root@Server01 ~]#setenforce  0
[root@Server01 ~]# systemctl  restart  httpd

第4步:在Client1上访问测试(Server01和Client1要保证可以互相通信)。

03 Apache配置—用户个人主页

例:在Apache服务器中,为系统中的long用户设置个人主页空间,该用户家目录为/home/long,个人主页空间所在目录为public_html。
第1步:修改用户家目录权限/home/www,其他用户拥有读取和执行的权限。
 

[root@Server01 ~]#useradd long
[root@Server01 ~]#passwd  long
[root@Server01 ~]# chmod  705  /hom/long

第2步:创建存放用户个人主页空间的目录。

[root@Server01 ~]# mkdir  /home/long/public_html

第3步:创建个人主页空间的默认首页文件。

[root@Server01 ~]# cd  /home/long/public_html
[root@Server01 public_html]# echo “this  is  long’s  web” >>index.html

第4步:httpd服务程序中,没有开启个人用户主页功能。修改配置文件/etc/httpd/conf.d/userdir.conf。
将UserDir  disabled参数前加上“#”,表示将httpd服务程序开启个人用户主页功能。
将UserDir  public_html参数前的“#”去掉,网站数据在用户主目录中保存在public_html目录下。
 

[root@Server01 ~]# vi /etc/httpd/conf.d/userdir.conf
……
#UserDir  disabled
……
UserDir  public_html

第5步:重启服务。

[root@Server01 ~]# systemctl  restart  httpd


第6步:在Client1上访问测试。
打开火狐,输入:服务器端IP地址\~long

  • 22
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值