Apache(httpd)安装和配置

一、什么是Apache?

         Apache(或httpd)服务,是Internet上使用最多的Web服务器技术之一,通俗来讲就是一个用于搭建网站的服务。作用解析网页语言,如html,php,jsp等、接收web用户的请求,并给予一定的响应。

有两个版本:

  • http:超文本传输协议,通过线路以明文形式发送,默认使用80端口/TCP
  • https:经TLS/SSL安全加密的超文本传输协议,默认使用443端口/TCP

二、Apache的配置文件

1、配置文件的位置
配置文件存放位置
服务目录 /etc/httpd
主配置文件 /etc/httpd/conf/httpd.conf
虚拟主机的配置文件目录 /etc/httpd/conf.d
基于用户的配置文件 /etc/httpd/conf.d/userdir.conf
日志文件目录 /etc/httpd/logs
默认的网站数据目录 /var/www/html

2、主配置文件的重要参数

主配置文件:/etc/httpd/conf/httpd.conf

参数作用参数作用
ServerRoot 服务目录 ServerName 网站服务器的域名
Listen 监听的IP地址与端口号 DocumentRoot 默认网站数据目录
User 运行服务的用户 Directory 文件目录的权限
Group 运行服务的用户组 DirectoryIndex 默认的索引页页面
ServerAdmin 管理员邮箱 ErrorLog 错误日志文件


      搭建Apache服务器

准备:配置网络; yum源; 一台Server端、一台Client端(图形)、一台Client端(命令)

任务一:配置简单的httpd服务

server端安装:

一、安装httpd服务

yum -y install httpd

rpm -qa | grep httpd

 

二、配置防火墙并重启服务

firewall-cmd --permanent --add-service=http

firewall-cmd --reload

systemctl restart httpd

systemctl enable httpd

Client端访问:

        有图形化(firefox):http://( Server ip)

         没有图形化: curl http://(Server ip)

 wind客户端测试:cmd -- curl http://(server IP)

 

任务二:配置基于用户的个人网站(已安装httpd服务)

server端配置:

一、新建用户(网站基于该用户)并修改用户网页文件访问权限

useradd lpm

passwd lpm

使其他用户具有读取和执行的权限: 

chmod -R 705 /home/lpm

二、创建个人网页文件

新建一个文件夹mkdir /home/lpm/public_html

到该路径下:   cd /home/lpm/public_html

写入内容:     echo "hello,欢迎访问lpm的个人网站">>index.html

三、修改基于用户的httpd配置文件

vim /etc/httpd/conf.d/userdir.conf

第17行,改为开启,表示开启个人用户主页功能:  UserDir enabled   

第24行,去注释,表示网站数据在用户家目录中的名称: UserDir public_html  

四、修改selinux权限、配置防火墙、重启

getsebool -a | grep home

setsebool httpd_enable_homedirs on

firewall-cmd --permanent --add-service=http

firewall-cmd --reload

systemctl restart httpd

 

Client端访问:

图形化:http://ip/~lpm/   (例:http://192.168.90.10/~lpm/)

命令行:curl http://ip/~lpmp/

 windows验证curl http://192.168.130.10/~lpm/

 

任务三:配置基于域名访问的虚拟机

1、新建虚拟主机的网页文件

2、配置虚拟主机的文件

3、做域名解析文件

4、配置防火墙(同上)

5、修改虚拟主机网页文件的selinux上下文类型

6、重启服务

7、使用浏览器访问

 

posted @ 2022-11-03 20:55  刘盘明  阅读(3071)  评论(0编辑  收藏  举报