Apache HTTP Server 的安装与配置

一、概要

1. 环境

(1) Rocky Linux 9.3

二、安装与配置

1. 安装

(1) 安装

bash 复制代码
sudo dnf install httpd -y

(2) 服务

bash 复制代码
sudo systemctl start httpd
sudo systemctl enable httpd
systemctl status httpd

(3) 防火墙

bash 复制代码
sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

2. SSL

(1) 安装SSL模块

bash 复制代码
sudo dnf install mod_ssl -y

安装完成之后会在/etc/httpd/conf.d目录下出现一个文件ssl.conf

(2) 为域名设置SSL/TLS

假设我们需要为www.example.com设置SSL/TLS:

a. 创建证书目录

bash 复制代码
sudo mkdir /etc/httpd/certs

b. 准备证书

OpenSSL 系列2 --- 应用

i. CA证书;

ii. 域名证书;

iii. 域名证书密钥;

c. 创建配置文件

bash 复制代码
sudo vi /etc/httpd/certs/www.example.com.conf

d. 初始化配置文件:

bash 复制代码
<VirtualHost *:443>
    ServerName ldapadmin.example.com
    SSLEngine on
    SSLVerifyClient optional
    SSLVerifyDepth 1
    SSLCACertificateFile "/etc/httpd/certs/cacert.pem"
    SSLCertificateFile "/etc/httpd/certs/www.example.com.cert.pem"
    SSLCertificateKeyFile "/etc/httpd/certs/key.pem"
</VirtualHost>

e. 重启服务

bash 复制代码
sudo systemctl restart httpd
systemctl status httpd

3. 强制HTTPS访问

(1) 编辑配置文件

bash 复制代码
sudo vi /etc/httpd/certs/www.example.com.conf

(2) 新增配置:

bash 复制代码
<VirtualHost *:80>
    ServerName www.example.com
    RewriteEngine on
    RewriteCond %{SERVER\_PORT} !^443$
    RewriteRule ^/?(.\*)$ https://%{SERVER\_NAME}/$1 \[L,R\]

    <Directory "${INSTALL\_DIR}/htocs"\>
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

4. 测试配置

bash 复制代码
apachectl configtest

三、引用

1. 官方

https://httpd.apache.org/

https://httpd.apache.org/docs/2.4/en/ssl/ssl_howto.html

转至:https://www.cnblogs.com/eagle6688/p/17891481.html

相关推荐
24zhgjx-fuhao31 分钟前
HTTP的配置
网络·网络协议·http
友莘居士1 小时前
Ganache-CLI以太坊私网JSON-RPC接口执行环境搭建
网络协议·rpc·json·环境搭建·以太坊
安卓开发者2 小时前
第14讲:HTTP网络请求 - Dio库的使用与封装
网络·网络协议·http
L.EscaRC2 小时前
【复习408】TCP运输层核心机制
网络协议·tcp/ip
红树林073 小时前
渗透测试之json_web_token(JWT)
网络协议·安全·web安全
2501_915918413 小时前
HTTP和HTTPS工作原理、安全漏洞及防护措施全面解析
android·http·ios·小程序·https·uni-app·iphone
梓沂4 小时前
MyBatis的默认对象工厂org.apache.ibatis.reflection.factory.ObjectFactory
apache·mybatis
北京耐用通信4 小时前
冶金车间“迷雾”重重?耐达讯自动化Profibus转光纤为HMI点亮“透视眼”!
人工智能·物联网·网络协议·网络安全·自动化
武子康4 小时前
大数据-150 Apache Druid 单机部署实战:架构速览、启动清单与故障速修
大数据·后端·apache
北京耐用通信4 小时前
耐达讯自动化Profibus光纤模块:智能仪表的“生命线”,极端环境通信无忧!
人工智能·物联网·网络协议·自动化·信息与通信