玩转rhel9 Apache

发布于:2025-07-13 ⋅ 阅读:(13) ⋅ 点赞:(0)

Apache的基本信息

/etc/httpd/conf     #apache的配置目录
/etc/http/conf.d     #子配置目录
/etc/httpd/conf/httpd.conf     #主配置文件
/lib/systemd/system/htpd.service     #启动文件
:80     #默认端口
/var/www/html     #默认发布目录
index.html     #默认发布文件

一、Apache 安装

在火墙中放行web服务:

开启服务:

生成默认测试页文件:

测试:

二、Apache的基本配置信息

1.端口修改

修改配置文件:

刷新服务:

设定火墙通过:

检测:

2.默认发布目录

建立默认发布目录:

修改主配置文件:

重启服务:

👇最好用systemctl reload httpd不停服务重新载入配置文件

生成默认发布目录测试文件:

测试:

3.默认发布文件

建立新的默认发布文件:

当没有对配置进行修改时新默认发布文件不会被默认访问:

修改主配置文件:

重载服务:

测试:

三、https

安装mod_ssl:

建立证书和key文件目录:

制作证书:

[root@apache ~]# openssl req \
-newkey rsa:2048 \
-nodes \
-sha256 \
-keyout /etc/httpd/certs/timinglee.org.key \
-x509 \
-days 365 \
-out /etc/httpd/certs/timinglee.org.crt
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shannxi
Locality Name (eg, city) [Default City]:XI'AN
Organization Name (eg, company) [Default Company Ltd]:timinglee
Organizational Unit Name (eg, section) []:webserver
Common Name (eg, your name or your server's hostname) []:www.timinglee.org
Email Address []:timinglee@timinglee.org

命令执行完成,证书出现:

编辑配置文件:

重启服务:

测试:在浏览器中访问

证书查看:

  

四、Apache的虚拟主机

为每个发布站点建立默认发布目录:

为每个站点建立默认发布文件:

修改配置文件:

👆

<VirtualHost _default_:80>
  DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
  ServerName bbs.zk.org
  DocumentRoot /var/www/virtual/zk.org/bbs/
</VirtualHost>

<VirtualHost *:80>
ServerName news.zk.org
DocumentRoot /var/www/virtual/zk.org/news/
</VirtualHost>

刷新服务:

测试:

1.在浏览器所在主机中手动编写本地解析文件

[root@apache ~]# vim /etc/hosts

2.测试效果

👺如果有问题检查主配置文件里的默认发布目录和授权


网站公告

今日签到

点亮在社区的每一天
去签到