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

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

相关推荐
猫头虎8 小时前
web开发常见问题解决方案大全:502/503 Bad Gateway/Connection reset/504 timed out/400 Bad Request/401 Unauthorized
运维·前端·nginx·http·https·gateway·openresty
伊织萌10 小时前
在 Ubuntu 22.04 上安装 PostgreSQL
linux·服务器·ubuntu·postgresql·云计算
ding_zhikai11 小时前
【个人日记】修复ubuntu屏幕显示不正常
linux·运维·ubuntu
rfidunion11 小时前
ubuntu下使用qemu模拟ARM(二)
linux·arm开发·ubuntu
zxdzxdzzxd11 小时前
解决Ubuntu虚拟机输入卡顿卡顿和鼠标滚轮不灵敏的问题
linux·ubuntu·计算机外设
dust_and_stars15 小时前
Ubuntu 24.04 安装配置 vscode-server
前端·ubuntu·eureka
无籽西瓜a15 小时前
SSL/TLS工作流程以及HTTP与HTTPS详解
http·https·ssl
只想恰口饭1 天前
程序人生-Hello’s P2P
linux·c语言·ubuntu
hoperest1 天前
程序人生-Hello‘s P2P
linux·c语言·程序人生·ubuntu
quixoticalYan1 天前
哈工大计算机系统大作业报告-程序人生-Hello’s P2P
linux·windows·程序人生·ubuntu·课程设计