linux red hat 8.0 搭建httpd服务

简介:

Apache HTTP Server(简称Apache),是Apache软件基金会的一个开源的网页服务器,可以在大多数电脑操作系统中运行,由于其具有的跨平台性和安全性,被广泛使用,是最流行的Web服务器端软件之一。

httpd服务主要文件

  • 主配置文件:/etc/httpd/conf/httpd.conf      //httpd最主要的配置文件
  • 扩展配置文件:/etc/httpd/conf.d/*.conf    //httpd的额外配置文件
  • 网页的存放目录:/var/www/html/
  • 模块的目录:/etc/httpd/modules/
  • 日志目录:/var/log/httpd/*
    • 访问日志为:./access_log
    • 错误日志为:./error_log

这篇文章将用小红帽操作系统来介绍httpd服务的相关操作顺便搭建一个简易的网页。

实验1:搭建一个简易网页

[root@serverA ~]# yum -y install httpd

httpd服务默认的网页存放路径在/var/www/html 下面

 然后重启服务

[root@serverA ~]# systemctl restart httpd

[root@serverA ~]# systemctl stop firewalld.service 
[root@serverA ~]# setenforce 0

在windows主机做测试

 实验2:实现相同的ip不同的端口访问

[root@serverA ~]# cd /etc/httpd/conf.d/
[root@serverA conf.d]# vim httpd-vhosts.conf    //新建并编写这个文件
#192.168.22.1:8080
Listen 8080
<VirtualHost 192.168.22.1:8080>
        ServerAdmin root@serverA
        ServerName www.zzc.com
        DocumentRoot "/var/www/html/"
        ErrorLog "/var/log/httpd/error_log"
        CustomLog "/var/log/httpd/access_log" combined
        <Directory "/var/www/html/">
                <RequireAll>
                        Require all granted
                </RequireAll>
        </Directory>
</VirtualHost>

 

 重启服务

[root@serverA conf.d]# systemctl restart httpd

 实验3:相同ip不同的端口访问不同的内容

[root@serverA ~]# cd /var/www/html/
[root@serverA html]# mkdir web
[root@serverA html]# cd web/
[root@serverA web]# echo 'hello world' > index.html
[root@serverA web]# cat index.html 
hello world

[root@serverA ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf 
#192.168.22.1:8080
Listen 8080
<VirtualHost 192.168.22.1:8080>
        ServerAdmin root@serverA
        ServerName www.zzc.com
        DocumentRoot "/var/www/html/web/"
        ErrorLog "/var/log/httpd/error_log"
        CustomLog "/var/log/httpd/access_log" combined
        <Directory "/var/www/html/web/">
                <RequireAll>
                        Require all granted
                </RequireAll>
        </Directory>
</VirtualHost>

 重启服务

 实验4:为保障网页安全,开启网页用户认证

[root@serverA ~]# htpasswd -c /etc/httpd/passwd zzc    //创建用户认证文件
New password:                                         //密码不显示
Re-type new password:                                 //确认密码
Adding password for user zzc
[root@serverA ~]# vim /etc/httpd/conf.d/userdir.conf 
17   #  UserDir disabled            //注释掉17行
24     UserDir html                    
31 <Directory "/var/www/html/">
将32-34行注释掉
35 AllowOverride all
36 authuserfile "/etc/httpd/passwd"
37 authname "zzc's home"        //认证的用户名
38 authtype basic            //认证类型
39 require user zzc

 重启服务

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值