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 . 测试效果

相关推荐
阿里云云原生3 小时前
Apache RocketMQ + “太乙” = 开源贡献新体验
apache·rocketmq
家里有只小肥猫10 小时前
开通保存图片权限
apache
Fantasy丶夜雨笙歌2 天前
Apache HTTP Server 从安装到配置
网络协议·http·apache
蠢货爱好者2 天前
一分钟快速了解Apache
apache
麟城Lincoln2 天前
【Linux-云原生-笔记】Apache相关
linux·笔记·云原生·apache·webserver
ZZZKKKRTSAE2 天前
玩转rhel9 Apache
linux·运维·服务器·apache·web
HashData酷克数据3 天前
Apache Cloudberry 向量化实践(二):如何识别和定位向量化系统的性能瓶颈?
apache
HashData酷克数据4 天前
流批一体的“奥卡姆剃刀”:Apache Cloudberry 增量物化视图应用解析
apache