Linux系统之Apache

什么是Apache

Apache HTTP Server(简称Apache):是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。
Apache的默认服务端口为:80

##Apache的默认设定

默认发布目录:/var/www/html/
默认访问页面:index.html 里面可以写东西,就会显示在网页
默认端口:80
默认安全上下文:http_sys_content_t
程序开启默认用户:apache
apache日志:/etc/httpd/logs/*
主配置目录:/etc/httpd/
主配置文件:/etc/httpd/conf/httpd.conf
子配置目录:/etc/httpd/conf.d
子配置文件:/etc/httpd/conf.d/*.conf

安装httpd服务

[root@http ~]# yum install httpd -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch             Version                 Repository       Size
================================================================================
Installing:
 httpd           x86_64           2.4.6-45.el7            rhel7           1.2 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.2 M
Installed size: 3.7 M
Downloading packages:
httpd-2.4.6-45.el7.x86_64.rpm                              | 1.2 MB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-2.4.6-45.el7.x86_64                                    1/1 
  Verifying  : httpd-2.4.6-45.el7.x86_64                                    1/1 

Installed:
  httpd.x86_64 0:2.4.6-45.el7                                                   

Complete!

##开启httpd
[root@http ~]# systemctl start httpd
##查看http服务端口
[root@http ~]# netstat -antuple | grep httpd
tcp6 0 0 :::80 ::? LISTEN 0 91836 3028/httpd
##进入http服务默认端口
[root@dhcp ~]# cd /var/www/html/
##编写http服务默认发布页面,该页面的内容访问时会出现
[root@http html]# vim index.html

<h1>hello wold!</h1>

##让火墙允许http服务通过
[root@http html]# firewall-cmd --permanent --add-service=http
success
##让火墙允许https服务通过
[root@http html]# firewall-cmd --permanent --add-service=https
success
##重启火墙服务
[root@http html]# firewall-cmd --reload
success
##查看火墙服务的状态
[root@http html]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcp dhcpv6-client ssh http https
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:

##验证是否成功
在这里插入图片描述

Apache的基本配置

##修改默认发布文件
##注释掉原来的 添加新的默认发布文件为cai.html
[root@http ~]# vim /etc/httpd/conf/httpd.conf
在这里插入图片描述
[root@http ~]# vim /var/www/html/cai.html
[root@http ~]# systemctl restart httpd.service
[root@http ~]# ls /var/www/html/
cai.html index.html
[root@http ~]# cat /var/www/html/cai.html
cai.westos.com
[root@http ~]# cat /var/www/html/index.html
hello wold!

测试:在网页上输入172.25.254.108后出现cai.html文件内容
在这里插入图片描述

##修改默认发布目录
##修改默认发布目录为/httphome/http/html,默认发布页面为tian.html
[root@http ~]# vim /etc/httpd/conf/httpd.conf
在这里插入图片描述
[root@http ~]# mkdir -p /httphome/http/html
[root@http ~]# vim /httphome/http/html/tian.html
[root@http ~]# systemctl restart httpd.service
[root@http ~]#cat/httphome/http/html/tian.html
tian.westos.com
测试:在网页上输入172.25.254.108/tian.html出现生日定后的页面
在这里插入图片描述
##Apache的端口设定
在Apache服务中,默认是80端口开放服务
我们可以通过修改配置文件修改默认端口
[root@http ~]# vim /etc/httpd/conf/httpd.conf
在这里插入图片描述
[root@http ~]# vim /etc/httpd/conf/httpd.conf
[root@http ~]# systemctl restart httpd.service
[root@http ~]# netstat -antuple | grep httpd
tcp6 0 0 :::8080 ::? LISTEN 0 133427 32724/httpd
[root@http ~]# firewall-cmd --permanent --add-port=8080/tcp
success
[root@http ~]# firewall-cmd --reload
success

测试:
默认为80端口,如果不加修改后的端口号,页面报错
在这里插入图片描述

添加8080端口号,页面出现
在这里插入图片描述

##apache的访问控制(设定ip的访问和设定用户的访问)
第一种:设定ip的访问
[root@http ~]# vim /etc/httpd/conf/httpd.conf
在这里插入图片描述
[root@http ~]# systemctl restart httpd.service

测试:
在ip为172.25.254.8的物理机中访问westos目录,被拒绝
在这里插入图片描述
在ip为172.25.254.108的物理机中,访问westos目录,成功
在这里插入图片描述

注意:如果顺序写错会被后写的覆盖

第二种:设定用户的访问

注意:htpasswd命令的参数:

-c:创建一个加密文件;
-
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值