1.Apache的作用
在web被访问时通常使用http://的方式
http:// ##超文本传输协议
http:// 超文本传输协议提供软件
Apache nginx stgw jfe Tengine
2.Apache的安装
dnf install httpd.x86_64 -y
3.Apache的启用
systemctl enable --now httpd ##开启服务并设定服务位开机启动
firewall-cmd --list-all ##查看火墙信息
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效
4.Apache的基本信息
服务名称:httpd
配置文件: /etc/httpd/conf/httpd.conf ##主配置文件
/etc/httpd/conf.d/*.conf ##子配置文件
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口:80 #http
443 #https
用户: apache
日志: /etc/httpd/logs
5.Apache的基本配置
下载安装
[root@westoslinux174 ~]# dnf install httpd -y 安装Apache
[[root@westoslinux174 ~]# systemctl enable --now httpd 开启服务并设定服务开机启动
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@westoslinux174 ~]# firewall-cmd --permanent --add-service=http 在火墙中永久开启http访问
success
[root@westoslinux174 ~]# firewall-cmd --reload 刷新火墙使设定生效
success
[root@westoslinux174 ~]# vim /var/www/html/index.html
<h1>hello westos</h1>
浏览器查看172.25.254.174 【hello westos】
端口更改
[root@westoslinux174 ~]vim /etc/httpd/conf/httpd.conf
Listen 8080
[root@westoslinux174 ~]systemctl restart httpd
[root@westoslinux174 ~]# netstat -antlupe | grep http
tcp6 0 0 :::8080 :::* LISTEN 0 87524 4864/httpd
浏览器172.25.254.174:8080 失败
[root@westoslinux174 ~]firewall-cmd --permanent --add-port=8080/tcp
[root@westoslinux174 ~]firewall-cmd --reload
浏览器172.25.254.174:8080 成功
[root@westoslinux174 ~]vim /etc/httpd/conf/httpd.conf 恢复80
[root@westoslinux174 ~]systemctl restart httpd
浏览器查看 172.25.254.174 成功
默认发布文件
[root@westoslinux174 ~]# cd /var/www/html/
[root@westoslinux174 html]# ls
index.html
[root@westoslinux174 html]# vim test.html
<h1>hello test</h1>
[root@westoslinux174 html]# cat test.html
hello test
浏览器查看 172.25.254.174/test.html 【hello test】
[root@westoslinux174 ~]vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex test.html index.html 按顺序查看
</IfModule>
[root@westoslinux174 ~]systemctl restart httpd
浏览器查看 172.25.254.174 成功 【hello test】
[root@westoslinux174 ~]rm -fr test.html
浏览器查看 172.25.254.174 【hello westos】