1.购买证书(免费的3个月有效期 到期更换 每年每个账号可申请20个免费)
2.自己充当CA机构生成假证
生成证书流程
1.创建存放证书的目录
[root@web01 ~]# mkdir -p /etc/nginx/ssl_key
[root@web01 ~]# cd /etc/nginx/ssl_key
[root@web01 ssl_key]#
2.生成证书
[root@web01 ssl_key]# openssl genrsa -idea -out server.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
..................................................+++++
.................................................................................................................................................................................................+++++
e is 65537 (0x010001)
Enter pass phrase for server.key: # 输入密码 1234
Verifying - Enter pass phrase for server.key: # 再次输入 1234
[root@web01 ssl_key]# ll
total 4
-rw------- 1 root root 1747 Dec 17 08:37 server.key
[root@web01 ssl_key]# openssl req -days 36500 -x509 \
> -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
Generating a RSA private key
...........................................................................+++++
..........+++++
writing new private key to 'server.key'
-----
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]:CN
Locality Name (eg, city) []:BJ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:oldboy
Organizational Unit Name (eg, section) []:oldboy
Common Name (e.g. server FQDN or YOUR name) []:CN
Email Address []:11@qq.com
[root@web01 ssl_key]# ll
total 8
-rw-r--r-- 1 root root 1367 Dec 17 08:40 server.crt
-rw------- 1 root root 1704 Dec 17 08:38 server.key
面试: 如何查看证书的有效时间
[root@web01 /etc/nginx/ssl_key]#openssl x509 -in server.crt -noout -enddate
notAfter=Mar 17 23:59:59 2025 GMT
Comments NOTHING