ubuntu 22.04通过apt-get安装的apache2将http改造为https的方法

目录

一、安装apache2

二、启动apache2服务

三、访问http网页

四、改造https

(一)查看apache2是否安装了ssl模块

(二)安装apache2-dev

(三)配置SSL访问

[1. 生成私有证书](#1. 生成私有证书)

[2. 新增ssl配置文件](#2. 新增ssl配置文件)

[3. 重启apache2服务,使用https访问网站](#3. 重启apache2服务,使用https访问网站)


一、安装apache2

复制代码
sudo apt-get install apache2

二、启动apache2服务

复制代码
sudo systemctl start apache2

三、访问http网页

四、改造https

(一)查看apache2是否安装了ssl模块

复制代码
sudo apache2ctl -M

命令查询到现有模块如下,未找到ssl相关模块

(二)安装apache2-dev

apache2-dev模块包含了ssl模块,安装后先载入ssl模块,再重启apache2服务:

复制代码
sudo a2enmod ssl

sudo systemctl restart apache2

已经成功加载ssl_module模块

(三)配置SSL访问

由于是测试环境,先自己生成证书,如生产环境,可导入企业证书。

1. 生成私有证书

复制代码
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.test.com"

2. 新增ssl配置文件

将默认default-ssl.conf配置文件拷贝到apache2的扩展目录下,

复制代码
sudo cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/

cd /etc/apache2/sites-enabled/

sudo vim default-ssl.conf

将配置中的证书文件改成自己的,以下是上面生成的私有证书:

SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt

SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

如果用自己的域名,配置文件需要加上ServerName

3. 重启apache2服务,使用https访问网站

复制代码
sudo systemctl restart apache2

生产站点的目录权限问题请自行处理。

相关推荐
sheeta19982 小时前
TypeScript references 配置与 emit 要求详解
javascript·ubuntu·typescript
ancktion2 小时前
ubuntu多gcc版本切换
linux·运维·ubuntu
贵沫末3 小时前
Claude Code使用
ubuntu
哇哦9823 小时前
渗透安全(渗透防御)③
安全·https·渗透·dns·渗透防御
Freak嵌入式4 小时前
aiohttps异步HTTPS库:uPyPI+MicroPython一键安装
人工智能·python·网络协议·http·https·micropython
DeepHacking4 小时前
Ubuntu 22.04 安装 Allow Locked Remote Desktop 扩展:解决锁屏后 mstsc 无法连接的问题
linux·运维·ubuntu
成为你的宁宁5 小时前
【apt update突然报错Temporary failure resolving ‘cn.archive.ubuntu.com‘】
linux·运维·ubuntu
木井巳5 小时前
【网络原理】初识相关概念
网络·网络协议·tcp/ip·http·https·udp
SilentSamsara14 小时前
SSH 远程管理:密钥登录 + 隧道转发,一次性配置好
linux·运维·服务器·ubuntu·centos·ssh