openssl生成自签证书
简介openssl生成自签证书
本文主要介绍使用openssl生成自签证书
生成CA证书私钥
[root@localhost openssl]# openssl genrsa -out ca.key 4096
Generating RSA private key, 4096 bit long modulus
....................................++
.............................................................................................++
e is 65537 (0x10001)
[root@localhost openssl]# ll
total 4
-rw-r--r-- 1 root root 3243 May 1 22:46 ca.key
生成CA证书
#这里需要调整-subj中的选项,CN可以只指定一个名称,固定的即可,但是这里指定了域名,这里有消息为3650天,也就是10年
[root@localhost openssl]# openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Sichuan/L=Chengdu/O=hi/OU=Personal/CN=hi-host.com" -key ca.key -out ca.crt
[root@localhost openssl]# ll
total 8
-rw-r--r-- 1 root root 2025 May 1 22:48 ca.crt
-rw-r--r-- 1 root root 3243 May 1 22:46 ca.key
生成服务器证书
证书通常包含一个.crt文件和一个.key文件,例如yourdomain.com.crt和yourdomain.com.key
#生成私钥
[root@localhost openssl]# openssl genrsa -out test.hi-host.com.key 4096
Generating RSA private key, 4096 bit long modulus
.............................................................................................................................................++
......................................................................................................................................................................................................++
e is 65537 (0x10001)
[root@localhost openssl]# ll
total 12
-rw-r--r-- 1 root root 2013 May 1 22:50 ca.crt
-rw-r--r-- 1 root root 3243 May 1 22:46 ca.key
-rw-r--r-- 1 root root 3243 May 1 22:50 test.hi-host.com.key
#生成证书签名请求(CSR),这里需要设置对应的域名
[root@localhost openssl]# openssl req -sha512 -new -subj "/C=CN/ST=SiChuan/L=Chengdu/O=example/OU=Personal/CN=hi-host.com" -key test.hi-host.com.key -out test.hi-host.com.csr
[root@localhost openssl]# ll
total 16
-rw-r--r-- 1 root root 2013 May 1 22:50 ca.crt
-rw-r--r-- 1 root root 3243 May 1 22:46 ca.key
-rw-r--r-- 1 root root 1704 May 1 22:53 test.hi-host.com.csr
-rw-r--r-- 1 root root 3243 May 1 22:50 test.hi-host.com.key
#生成一个x509 v3扩展文件
[root@localhost openssl]# cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1=test.hi-host.com
EOF
#上面可以设置多个域名,DNS.2,DNS.3等,可以是不同的域名
[root@localhost openssl]# ll
total 20
-rw-r--r-- 1 root root 2013 May 1 22:50 ca.crt
-rw-r--r-- 1 root root 3243 May 1 22:46 ca.key
-rw-r--r-- 1 root root 1704 May 1 22:53 test.hi-host.com.csr
-rw-r--r-- 1 root root 3243 May 1 22:50 test.hi-host.com.key
-rw-r--r-- 1 root root 235 May 1 22:55 v3.ext
#使用该v3.ext文件为您的主机生成证书
[root@localhost openssl]# openssl x509 -req -sha512 -days 3650 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in test.hi-host.com.csr -out test.hi-host.com.crt
Signature ok
subject=/C=CN/ST=SiChuan/L=Chengdu/O=example/OU=Personal/CN=hi-host.com
Getting CA Private Key
[root@localhost openssl]# ll
total 28
-rw-r--r-- 1 root root 2013 May 1 22:50 ca.crt
-rw-r--r-- 1 root root 3243 May 1 22:46 ca.key
-rw-r--r-- 1 root root 17 May 1 22:56 ca.srl
-rw-r--r-- 1 root root 2057 May 1 22:56 test.hi-host.com.crt
-rw-r--r-- 1 root root 1704 May 1 22:53 test.hi-host.com.csr
-rw-r--r-- 1 root root 3243 May 1 22:50 test.hi-host.com.key
-rw-r--r-- 1 root root 235 May 1 22:55 v3.ext
配置nginx
[root@localhost openssl]# vim /etc/nginx/conf.d/test.hi-host.com.conf
server {
listen 443 ssl;
server_name test.hi-host.com;
client_max_body_size 1000m;
ssl_certificate /root/openssl/test.hi-host.com.crt;
ssl_certificate_key /root/openssl/test.hi-host.com.key;
location / {
proxy_pass http://127.0.0.1:180;
}
}
#重启nginx
解决浏览器访问https不安全问题
以上配置好后,就可以访问域名https://test.hi-host.com ,但是这里访问的时候还是提示不安全,但是能看到有证书,证书无效,这就是自签证书会有这样的问题。所以我们需要将ca.crt证书导入到浏览器中,这里以chrome为例,设置步骤如下:
- 设置
- 搜索https—->管理证书
- 选择受信任根证书颁发机构
- 导入ca.crt
- 重启浏览器
- 重新访问
Expanded组件是flutter中使用率很高的一个组件,它可以动态调整child组件沿主轴的尺寸,比如填充剩余空间,比如设置尺寸比例。它常常和Row或Column组合起来使用。
《康熙王朝》是一部非常优秀的电视连续剧,陈道明演的康熙是我觉得最有帝王气魄,让人意犹未尽,本文主要记录一小段非常经典的对白。
Ansible-tower工具搭建和使用
《Dream It Possible》是一首由崔迪编曲,Andy Love谱曲填词,授权给世界各地歌手演唱的歌曲,是华为消费者业务品牌主题曲。歌曲中文版本为《我的梦》由张靓颖演唱。
HTTPie (发音是 aitch-tee-tee-pie) 是一个 HTTP 命令行客户端。HTTPie 工具是现代的 HTTP 命令行客户端,它能通过命令行界面与 Web 服务进行交互。它提供一个简单的 http 命令,允许使用简单而自然的语法发送任意的 HTTP 请求,并会显示彩色的输出。HTTPie 能用于测试、调试及与 HTTP 服务器交互。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。