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

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

相关推荐
森G18 小时前
七、04ledc-sdk--------makefile有变化
linux·c语言·arm开发·c++·ubuntu
生活很暖很治愈20 小时前
Linux——孤儿进程&进程调度&大O(1)调度
linux·服务器·ubuntu
getapi1 天前
注塑件的费用构成
linux·服务器·ubuntu
lucky-billy1 天前
Ubuntu 下一键部署 ROS2
linux·ubuntu·ros2
阿梦Anmory1 天前
Ubuntu配置代理最详细教程
linux·运维·ubuntu
getapi1 天前
Ubuntu 22.04 服务器的系统架构是否为 amd64 x86_64
linux·服务器·ubuntu
win x1 天前
深入理解HTTPS协议加密流程
网络协议·http·https
仙俊红1 天前
从 Filter / Interceptor 到 HTTPS
网络协议·http·https
游戏开发爱好者81 天前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
小天源1 天前
Cacti在Debian/Ubuntu中安装及其使用
运维·ubuntu·debian·cacti