在debian10系统上通过apache部署HTTPS网站,实现https部署测试工具Dvwa

2023-05-16

本文主要内容为:通过 OpenSSL 自建 CA来自签名证书 和 颁发SSL 证书实现 HTTPS(SSL)服务。

实现效果预览

在这里插入图片描述

1、安装apache2

1.1、安装

apt install apache2

在这里插入图片描述

1.2、停止运行

执行命令:

/etc/init.d/apache2 stop

效果:

 root@YY:/# /etc/init.d/apache2 stop
[ ok ] Stopping Apache httpd web server: apache2.

2、自建CA

2.1、创建文件夹

执行下面的命令创建相关文件夹:

mkdir -p /etc/apache2/ownSSL/{CA,Server}
cd /etc/apache2/ownSSL/

执行效果:

root@YY:~# mkdir -p /etc/apache2/ownSSL/{CA,Server}
root@YY:~# cd /etc/apache2/ownSSL/
root@YY:/etc/apache2/ownSSL# ls
CA  Server
root@YY:/etc/apache2/ownSSL# 

文件夹作用:

文件夹作用
/etc/apache2/ownSSL/CA存放CA私匙、CA 证书请求、CA根证书
/etc/apache2/ownSSL/Server包含Server私匙、Server证书请求、Server证书

2.2、生成 CA 私匙

执行下面的命令

cd /etc/apache2/ownSSL
openssl genrsa -out CA/CA_private.key 2048

执行效果:
在这里插入图片描述

2.3、生成 CA 证书请求

执行下面的命令:

openssl req -new -key CA/CA_private.key -out CA/CA_request.csr

在这个过程中,程序会提示需要你输入该根证书相关信息,请自行更改:
我的生成过程:

root@YY:/etc/apache2/ownSSL# openssl req -new -key CA/CA_private.key -out CA/CA_request.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GuangXi
Locality Name (eg, city) []:NanNing
Organization Name (eg, company) [Internet Widgits Pty Ltd]:spzx
Organizational Unit Name (eg, section) []:spzx
Common Name (e.g. server FQDN or YOUR name) []:spzx
Email Address []:admin@spzx.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:spzx
An optional company name []:spzx
root@YY:/etc/apache2/ownSSL# 

2.4、生成 CA 根证书

执行下面的命令:

openssl x509 -req -in CA/CA_request.csr \
 -extensions v3_ca \
 -signkey CA/CA_private.key \
 -out CA/CA_root.crt

执行过程:

root@YY:/etc/apache2/ownSSL# openssl x509 -req -in CA/CA_request.csr \
>  -extensions v3_ca \
>  -signkey CA/CA_private.key \
>  -out CA/CA_root.crt
Signature ok
subject=C = CN, ST = GuangXi, L = NanNing, O = spzx, OU = spzx, CN = spzx, emailAddress = admin@spzx.com
Getting Private key
root@YY:/etc/apache2/ownSSL# 

3、自建 Server 端证书

3.1、生成 Server 私匙

执行:

openssl genrsa -out Server/Server_private.key 2048

执行结果:

root@YY:/etc/apache2/ownSSL# openssl genrsa -out Server/Server_private.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
...............+++++
.....................+++++
e is 65537 (0x010001)
root@YY:/etc/apache2/ownSSL# 

3.2、 生成 Server 证书请求

openssl req -new -key Server/Server_private.key -out Server/Server_request.csr

执行过程

root@YY:/etc/apache2/ownSSL# openssl req -new -key Server/Server_private.key -out Server/Server_request.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GuangXi                                                                                                                                                              
Locality Name (eg, city) []:NanNing                                                                                                                                                                                  
Organization Name (eg, company) [Internet Widgits Pty Ltd]:spzx                                                                                                                                                      
Organizational Unit Name (eg, section) []:spzx                                                                                                                                                                       
Common Name (e.g. server FQDN or YOUR name) []:spzx                                                                                                                                                                  
Email Address []:admin@spzx.com                                                                                                                                                                                      
                                                                                                                                                                                                                     
Please enter the following 'extra' attributes                                                                                                                                                                        
to be sent with your certificate request                                                                                                                                                                             
A challenge password []:spzx                                                                                                                                                                                         
An optional company name []:spzx                                                                                                                                                                                     
root@YY:/etc/apache2/ownSSL#        

3.3、生成 Server 证书

新建文件

touch /etc/apache2/ownSSL/openssl.cnf 

然后写入内容(请根据自己的实际信息更改)

[req]  
distinguished_name = req_distinguished_name  
req_extensions = v3_req  

[req_distinguished_name]  
countryName = CN
countryName_default = CN  
stateOrProvinceName = GuangXi
stateOrProvinceName_default = NanNing
localityName = NanNing
localityName_default = NanNing
organizationalUnitName  = spzx
organizationalUnitName_default  = Domain Control Validated  
commonName = Internet Widgits Ltd  
commonName_max  = 64  

[ v3_req ]  
# Extensions to add to a certificate request  
basicConstraints = CA:FALSE  
keyUsage = nonRepudiation, digitalSignature, keyEncipherment  
subjectAltName = @alt_names  

[alt_names]  
# 注意这个IP.1的设置,IP地址需要和你的服务器的监听地址一样 DNS为server网址
IP.1 = 3.3.3.2
DNS.1 = 3.3.3.2

需要将 Server 监听的地址写入证书中,如果访问时地址与证书中地址不一致将不能通过证书认证。
实现效果:

root@YY:/etc/apache2/ownSSL# cat /etc/apache2/ownSSL/openssl.cnf 
[req]  
distinguished_name = req_distinguished_name  
req_extensions = v3_req  

[req_distinguished_name]  
countryName = CN
countryName_default = CN  
stateOrProvinceName = GuangXi
stateOrProvinceName_default = NanNing
localityName = NanNing
localityName_default = NanNing
organizationalUnitName  = spzx
organizationalUnitName_default  = Domain Control Validated  
commonName = Internet Widgits Ltd  
commonName_max  = 64  

[ v3_req ]  
# Extensions to add to a certificate request  
basicConstraints = CA:FALSE  
keyUsage = nonRepudiation, digitalSignature, keyEncipherment  
subjectAltName = @alt_names  

[alt_names]  
IP.1 = 3.3.3.2
DNS.1 = 3.3.3.2
root@YY:/etc/apache2/ownSSL# 

执行命令生成 Server 证书

openssl x509 -days 365 -req \
-in /etc/apache2/ownSSL/Server/Server_request.csr \
-extensions  v3_req -CAkey /etc/apache2/ownSSL/CA/CA_private.key \
-CA /etc/apache2/ownSSL/CA/CA_root.crt \
-CAcreateserial -out /etc/apache2/ownSSL/Server/Server_root.crt  \
-extfile /etc/apache2/ownSSL/openssl.cnf

实现效果:

root@YY:~# openssl x509 -days 365 -req \
> -in /etc/apache2/ownSSL/Server/Server_request.csr \
> -extensions  v3_req -CAkey /etc/apache2/ownSSL/CA/CA_private.key \
> -CA /etc/apache2/ownSSL/CA/CA_root.crt \
> -CAcreateserial -out /etc/apache2/ownSSL/Server/Server_root.crt  \
> -extfile /etc/apache2/ownSSL/openssl.cnf
Signature ok
subject=C = CN, ST = GuangXi, L = NanNing, O = spzx, OU = spzx, CN = spzx, emailAddress = admin@spzx.com
Getting CA Private Key
root@YY:~# 

4、Apache2 SSL 证书加载

4.1、停止服务运行(重要)

/etc/init.d/apache2 stop

执行过程

root@YY:~# /etc/init.d/apache2 stop
[ ok ] Stopping Apache httpd web server: apache2.
root@YY:~# /etc/init.d/apache2 status
[FAIL] apache2 is not running ... failed!
root@YY:~# 

4.2、启用SSL模块

a2enmod ssl

效果:

root@YY:~# a2enmod ssl
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  service apache2 restart
root@YY:~# 

然后根据提示信息重启服务,然后继续停止服务(别问,问就是机密)

/etc/init.d/apache2 restart
/etc/init.d/apache2 stop

效果:

root@YY:~# /etc/init.d/apache2 restart
[....] Restarting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
. ok 
root@YY:~# /etc/init.d/apache2 stop
[....] Stopping Apache httpd web server: apache2
. ok 
root@YY:~# 

4.3、加载 SSL 配置文件 default-ssl.conf

执行:

a2ensite default-ssl

效果:

root@YY:~# a2ensite default-ssl
Enabling site default-ssl.
To activate the new configuration, you need to run:
  service apache2 reload
root@YY:~# 

然后提示重新加载配置,执行下面的命令

/etc/init.d/apache2 reload
/etc/init.d/apache2 restart

效果

root@YY:~# /etc/init.d/apache2 reload
[FAIL] Reloading Apache httpd web server: apache2 failed!
[warn] Apache2 is not running ... (warning).
root@YY:~# /etc/init.d/apache2 restart
[....] Restarting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
. ok 
root@YY:~# 

5、Apache2 SSL 证书配置

5.1、添加监听端口

Listen 80基础上添加443端口

 vim /etc/apache2/ports.conf

效果:

root@YY:~# cat /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80 443

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
root@YY:~# 

5.2、修改 SSL 配置文件 default-ssl.conf

找到ServerAdmin(第三行),然后在下一行添加内容,根据下面的格式添加服务器
服务器域名/IP也就是前面设置的:DNS.0 的值

ServerName <服务器域名/IP>

实现效果:

                ServerAdmin webmaster@localhost
                ServerName 3.3.3.3
                DocumentRoot /var/www/html

然后保存退出

6、验证

6.1、重启服务

 /etc/init.d/apache2 restart

效果:

root@YY:~#  /etc/init.d/apache2 restart
[....] Restarting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
. ok 
root@YY:~# 

6.2、访问

https://localhost/login.php

在这里插入图片描述
然后就可以啦

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在debian10系统上通过apache部署HTTPS网站,实现https部署测试工具Dvwa 的相关文章

  • vmware中如何让虚拟机和物理主机在同一网段

    vmware中如何让虚拟机和物理主机在同一网段呢 比如物理主机的IP是192 168 1 10 xff0c 虚拟机主机的IP设置成192 168 1 20 xff0c 两者之间能够相互PING通 如何设置呢 xff0c 下面由小编介绍下具体
  • wait函数详解

    include lt sys types h gt 提供类型pid t的定义 include lt sys wait h gt pid t wait int status 进程一旦调用了wait xff0c 就立即阻塞自己 xff0c 由w
  • vscode使用虚拟环境

    我的conda没有添加入path xff0c 每次打开总是报错 一 选择对应虚拟环境的解释器 1 点击vscode的右下角这里 2 点击后可能会在vscode上方出现下图样子 xff0c 如果出现下图 xff0c 则点击第二项Select
  • TabError: inconsistent use of tabs and spaces in indentation

    错误原因是tab制表符和空格混用了 从其他地方复制源码容易出现此错误 解决办法 xff1a 把处于同级缩进的所有缩进修改统一 比较流行的几个编辑器都能标识tab和空格 xff0c 比如我用的vscode 用鼠标框选 不知道是tab还是空格的
  • 关于深度学习的问题笔记

    感谢沐神教我深度学习 x1f64f 损失为什么要平均 xff1f 平均即除以batch size xff0c 若不除 xff0c 则批越大梯度越大 xff0c 梯度下降的步长就越大 除以batch size可使梯度与批大小无关 也可以不在损
  • ubuntu安装应用未满足依赖问题的解决方案

    一 解决安装 deb文件因不满足以来而无法安装的问题 我们以安装freedownloadmanager deb这个安装包为例 xff0c 这种安装包用dpkg来安装 xff0c 一开始我们是这样安装的 xff1a span class to
  • 通讯协议(四)——SPI通信

    SPI是串行外设接口 xff08 Serial Peripheral Interface xff09 xff0c 是一种高速的 全双工 同步的串行通信总线 SPI采用的是一种主从方式工作 xff0c 一般有一个主设备和一个或多个从设备 SP
  • “当前不会命中断点,还没有为该文档加载任何符号“的最简单解决方案

    问题如下 xff0c 在vs2022启动源代码调试的时候 xff0c 发现打的断点调试的位置是白色叹号 xff0c 如下图 xff1a 这个问题很明显是项目中勾选了调试优化的选项 xff0c 导致无法调试 但是我的控制器中的代码 xff0c
  • 看大神如何使用sublime玩单片机

    keil uvision看厌了么 xff1f 试试Sublime Text吧 xff01 来源 xff1a Dawn L 阅读 xff1a 745 时间 xff1a 2016 01 23 16 18 分享 xff1a 之前用Sublime
  • 树莓派4B固定IP地址

    方法1 在 etc network interfaces d 目录下添加固定IP地址的脚本配置文件 将下面的配置保存为 eth0 xff0c 然后放到 etc network interfaces d 目录下就可以了 eth0网卡接口配置
  • 卓岚联网模块连接三菱FX系列PLC应用实例

    原文地址 卓岚联网模块连接三菱FX系列PLC应用实例 本案例使用FX3u 16M以及卓岚产品ZLAN5103 xff0c 实现GX Works通过虚拟串口监控PLC 一 PLC通讯口 圆头8孔RS422接口 xff0c 线序如下 xff1a
  • C++枚举enum使用详解

    目录 一 什么是枚举enum WHAT 二 使用枚举enum的场景 WHEN and WHERE 三 如何使用枚举enum HOW 1 xff09 枚举的定义 2 xff09 枚举的初始化 3 xff09 指定枚举类型 4 声明枚举对象 5
  • 国内现在web前端高手薪资都拿多少?

    不同城市薪资标准差别很大 xff0c 不限定条件拿个例来说太过儿戏 仅说国内来说一线城市 xff0c 普通本科普通打工人的情况 xff1a 一年以内工作经验月薪10k上下浮动 1 3年15k上下浮动 3 5年18 30k 5年以上差别很大
  • VScode上面的提示错误的红色浪线消失了,不小心点黄色灯泡给disable掉了,恢复办法

    启用方法是ctrl 43 shift 43 p 搜索 启用错误波形曲线 xff0c 打开就行
  • [我叫以赏]Python获取B站UP主粉丝数

    前言 不少人对B站粉丝数有着强烈的 控制感 xff0c 特别是B站用户 老番茄 的粉丝数要达到1000万了 xff0c 不少人想要见到突破1000w粉的那一瞬间 xff0c 虽然有很多网站提供了B站粉丝走图 粉丝统计等功能但是谁不想知道后面
  • Java语言写的一个简单的加密解密方法

    出处 使用方法 xff1a 加密方法 String cipherte 61 Enande encrypt content pass xff1b 解密方法 Enande decrypt ciphertext pass xff1b conten
  • 变更 Windows Server网络类别(共用、专用)

    若要快速切换为网络类型的话 xff0c 使用命令行操作 xff0c 1 利用 Windows PowerShell 来做切换了 我们点选一下工作列上的 Windows PowerShell 图示 xff0c 这时候就会开启 Windows
  • 【docker】3090显卡对应docker中cuda版本

    1 问题 想要将cuda9 0的docker部署到3090上 xff0c 尝试多次重新安装pytorch xff0c 但是都出现问题 xff1a RuntimeError cuda runtime error 8 invalid devic
  • 个人服务器搭建过程(win10+ubuntu server虚拟机)

    文章目录 前言1 资源链接 2 镜像制作3 系统安装4 win10开启ftp5 win10开启文件共享6 比特彗星安装配置7 nextcloud安装配置8 jellyfin安装配置9 tinyMediaManager安装配置10 打卡环境配
  • 【原创】2022年linux环境下QT6不支持中文输入法解决方案

    1 配置环境 export PATH 61 34 目录 Qt 6 x x gcc 64 bin 34 PATH export PATH 61 34 目录 Qt Tools Cmake bin 34 PATH 目录 gt 自己的安装目录 6

随机推荐