Apache部署

1.关于Apache

#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 # 默认发布文件

2.Apache安装

安装 apache

bash 复制代码
dnf install httpd -y

在火墙中放行 web 服务

bash 复制代码
firewall-cmd --permanent --add-service=http 

firewall-cmd --permanent --add-service=https

开启服务

bash 复制代码
systemctl  enable --now httpd

生成默认测试页文件并进行测试

bash 复制代码
echo 172.25.254.128 > /var/www/html/index.html
bash 复制代码
curl 172.25.254.128

3.Apache****的基本配置信息

修改配置文件

bash 复制代码
vim /etc/httpd/conf/httpd.conf 

刷新服务

bash 复制代码
systemctl reload httpd

设定火墙通过

bash 复制代码
firewall-cmd --permanent --add-port=8080/tcp

重启防火墙:

bash 复制代码
firewall-cmd --reload

检测

bash 复制代码
curl 172.25.254.128:8080

在ip为172.25.254.128的机器上测试:

在ip为172.25.254.30的机器上测试:

4.修改默认发布目录

建立默认发布目录

bash 复制代码
mkdir /web/html -p

修改配置文件

bash 复制代码
vim /etc/httpd/conf/httpd.conf

重启服务:

bash 复制代码
systemctl restart httpd

为进行测试,对新的html文件填入内容:

bash 复制代码
echo "/web/html!" > /web/html/index.html

进行测试:

建立新的默认发布文件

bash 复制代码
echo "rin!!!" > /web/html/rin.html

当没有对配置进行修改时新默认发布文件不会被默认访问,测试结果访问的还是index.html

只有指定访问时才能访问到rin.html文件

修改配置文件

bash 复制代码
vim /etc/httpd/conf/httpd.conf

重启服务

bash 复制代码
systemctl reload httpd

测试:

bash 复制代码
curl 172.25.254.128:8080

5.https

安装 mod_ssl

bash 复制代码
 dnf install mod_ssl -y

建立证书和 key 文件目录

bash 复制代码
mkdir /etc/httpd/certs
bash 复制代码
openssl req \
> -newkey rsa:2048 \
> -nodes \
> -sha256 \
> -keyout /etc/httpd/certs/rin.org.key \
> -x509 \
> -days 365 \
> -out /etc/httpd/certs/rin.org.crt

输入后会出现以下文字提示框,含义如下表所示:

Country Name (2 letter code) XX:CN

State or Province Name (full name) \[\]:shanxi

Locality Name (eg, city) Default City:xian

Organization Name (eg, company) Default Company Ltd:rin

Organizational Unit Name (eg, section) \[\]:webserver

Common Name (eg, your name or your server's hostname) \[\]:www.rin.org

Email Address \[\]:rin@rin.org

字段 含义说明 你的配置值
Country Name (2 letter code) 国家代码(2 个字母) CN(中国)
State or Province Name 省 / 自治区名称(全称) shanxi(山西省)
Locality Name 城市名称 xian(西安市,注:正确拼音为 Xi'an)
Organization Name 组织 / 公司名称 rin(你的组织名)
Organizational Unit Name 部门 / 单位名称 webserver(Web 服务器部门)
Common Name 通用名称(通常是服务器域名或主机名) www.rin.org(你的域名)
Email Address 联系邮箱 rin@rin.org(你的邮箱)

完成后能看到证书出现:

编辑主配置文件

bash 复制代码
vim /etc/httpd/conf.d/ssl.conf

注意:原证书链接要注释掉:

重启服务

bash 复制代码
systemctl reload httpd
bash 复制代码
netstat -antlupe | grep httpd

端口改为80:

在浏览器中访问

https:// 服务器 ip

6.apache的虚拟主机

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

bash 复制代码
 mkdir -p /var/www/virtual/rin.org/news
 mkdir -p /var/www/virtual/rin.org/bbs

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

bash 复制代码
echo new.rin.org > /var/www/virtual/rin.org/news/index.html
echo bbs.rin.org > /var/www/virtual/rin.org/bbs/index.html

修改配置文件

bash 复制代码
vim /etc/httpd/conf.d/vhosts.conf

刷新服务

bash 复制代码
 systemctl reload httpd

测试:

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

bash 复制代码
vim /etc/hosts

2 . 测试效果

相关推荐
网络豆6 天前
Apache Maven 鸿蒙 PC 适配全记录:把 JVM 构建工具交付到 HiShell
maven·apache·harmonyos
网络豆6 天前
Apache Hive 鸿蒙 PC 适配全记录:以 Qt 客户端打通 HiveQL、监控与元数据访问
hive·apache·harmonyos
网络豆6 天前
Apache HBase 鸿蒙 PC 适配全记录:用 Qt 原生客户端打通 REST 管理与数据读写
apache·hbase·harmonyos
无巧不成书02187 天前
Apache Tomcat 9 下载全指南(Windows,Linux,macOS):版本选型、国内镜像、SHA-512 与 PGP 完整性校验
windows·tomcat·apache
Dream-Y.ocean7 天前
鸿蒙平台 Apache Tomcat 管理控制台适配实战:基于 Electron 壳方案的真实 HTTP 服务器实现
tomcat·apache·harmonyos
betazhou7 天前
Apache seatunel常用配置参数解析说明
apache·seatunnel
凤山老林8 天前
Spring Boot 集成 Apache Kafka Streams 构建流处理应用:状态存储、窗口聚合与
spring boot·kafka·apache
DolphinScheduler社区9 天前
Apache DolphinScheduler 8 月报:权限安全加固,调度补火上线,性能与稳定性持续提升
大数据·安全·开源·apache·任务调度·海豚调度
sbjdhjd9 天前
从 7 字符文件名拼接到二维数组取值:PHP 无参函数限制下的受控靶场复盘 | (7字符绕过)
网络·nginx·安全·网络安全·云计算·php·apache
Jackyzhe10 天前
Apache Iceberg Variant 类型:v3 半结构化数据不再「二选一」
apache