Linux Nginx&HTTPS——构建私有的 CA认证 机构(私有ssl证书安全方案)

构建私有的 CA 机构

CA中心申请证书的流程:
过程:

1、web服务器,生成一对非对称加密密钥(web公钥,web私钥)
2、web服务器使用 web私钥生成 web服务器的证书请求文件,并将证书请求发给CA服务器
3、CA服务器使用 CA的私钥 对 web 服务器的证书请求进行数字签名得到 web服务器的数字证书,并将web服务器的数字证书颁发给web服务器

1、CA 介绍
CA(Certificate Authority)证书颁发机构主要负责证书的颁发、管理以及归档和吊销。证书内包含了拥有证书者的姓名、地址、电子邮件帐号、公钥、证书有效期、发放证书的CA、CA的数字签名等信息。
证书主要有三大功能:加密、签名、身份验证。

2、构建私有 CA
1、检查安装 openssl
[root@https-ca ~]# rpm -qa openssl
图片: https://uploader.shimo.im/f/gLwi6OP9iuvGAKnX.png

[root@https-ca ~]# yum install openssl openssl-devel -y #如果未安装
2、查看配置文件
openssl 配置/etc/pki/tls/openssl.cnf有关CA的配置。如果服务器为证书签署者的身份那么就会用到此配置文件,此配置文件对于证书申请者是无作用的。

[root@https-ca ~]# vim /etc/pki/tls/openssl.cnf
####################################################################
[ ca ]
default_ca      = CA_default            # 默认的CA配置;CA_default指向下面配置块####################################################################
[ CA_default ]dir             = /etc/pki/CA           # CA的默认工作目录
certs           = $dir/certs            # 认证证书的目录
crl_dir         = $dir/crl              # 证书吊销列表的路径
database        = $dir/index.txt        # 数据库的索引文件
​
​
new_certs_dir   = $dir/newcerts         # 新颁发证书的默认路径
​
certificate     = $dir/cacert.pem       # 此服务认证证书,如果此服务器为根CA那么这里为自颁发证书
serial          = $dir/serial           # 下一个证书的证书编号
crlnumber       = $dir/crlnumber        # 下一个吊销的证书编号
                                        
crl             = $dir/crl.pem          # The current CRL
private_key     = $dir/private/cakey.pem# CA的私钥
RANDFILE        = $dir/private/.rand    # 随机数文件
​
x509_extensions = usr_cert              # The extentions to add to the cert
​
name_opt        = ca_default            # 命名方式,以ca_default定义为准
cert_opt        = ca_default            # 证书参数,以ca_default定义为准
​
​
default_days    = 365                   # 证书默认有效期
default_crl_days= 30                    # CRl的有效期
default_md      = sha256                # 加密算法
preserve        = no                    # keep passed DN ordering
​
​
policy          = policy_match          #policy_match策略生效# For the CA policy
[ policy_match ]
countryName             = match         #国家;match表示申请者的申请信息必须与此一致
stateOrProvinceName     = match         #州、省
organizationName        = match         #组织名、公司名
organizationalUnitName  = optional      #部门名称;optional表示申请者可以的信息与此可以不一致
commonName              = supplied
emailAddress            = optional
# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]                     #由于定义了policy_match策略生效,所以此策略暂未生效
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

3、根证书服务器目录
根CA服务器:因为只有 CA 服务器的角色,所以用到的目录只有/etc/pki/CA
网站服务器:只是证书申请者的角色,所以用到的目录只有/etc/pki/tls

4、创建所需要的文件

[root@https-ca ~]# cd /etc/pki/CA/
[root@https-ca CA]# ls
certs  crl  newcerts  private
[root@https-ca CA]# touch index.txt   #创建生成证书索引数据库文件
[root@https-ca CA]# ls
certs  crl  index.txt  newcerts  private
[root@https-ca CA]# echo 01 > serial   #指定第一个颁发证书的序列号
[root@https-ca CA]# ls
certs  crl  index.txt  newcerts  private  serial
[root@https-ca CA]# 

5、创建密钥
在根CA服务器上创建密钥,密钥的位置必须为/etc/pki/CA/private/cakey.pem,这个是openssl.cnf中中指定的路径,只要与配置文件中指定的匹配即可。

[root@https-ca CA]# (umask 066; openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
...........+++
...............+++  
e is 65537 (0x10001)

6、生成自签名证书
根CA自签名证书,根CA是最顶级的认证机构,没有人能够认证他,所以只能自己认证自己生成自签名证书。

[root@https-ca CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem -days 7300
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) [XX]:CN
State or Province Name (full name) []:BEIJING
Locality Name (eg, city) [Default City]:BEIJING
Organization Name (eg, company) [Default Company Ltd]:CA
Organizational Unit Name (eg, section) []:OPT
Common Name (eg, your name or your server's hostname) []:ca.vc.com
Email Address []:
[root@https-ca CA]# ls
cacert.pem  certs  crl  index.txt  newcerts  private  serial
-new:   生成新证书签署请求
-x509:  专用于CA生成自签证书
-key:   生成请求时用到的私钥文件
-days : 证书的有效期限
-out /PATH/TO/SOMECERTFILE:     证书的保存路径

7、下载安装证书
/etc/pki/CA/cacert.pem就是生成的自签名证书文件,使用 SZ/xftp工具将他导出到窗口机器中。然后双击安装此证书到受信任的根证书颁发机构

[root@https-ca CA]# yum install -y lrzsz
[root@https-ca CA]# sz cacert.pem

证书导入:

浏览器设置——管理证书——受信任的证书颁发机构——导入——不断下一步——导入保存即可。

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Linux上安装SSL证书并配置Nginx,请按照以下步骤进行操作: 1. 获取SSL证书: - 您可以购买SSL证书,或者使用免费的Let's Encrypt证书。如果您选择使用Let's Encrypt证书,可以使用Certbot工具来获取和管理证书。 - 在这里,我将假设您已经获得了证书文件(.crt)和私钥文件(.key)。 2. 将证书和私钥文件上传到服务器: - 将证书和私钥文件上传到服务器上的某个目录,例如`/etc/nginx/ssl/`。 3. 配置Nginx以使用SSL证书: - 打开Nginx的配置文件,通常是`/etc/nginx/nginx.conf`或`/etc/nginx/conf.d/default.conf`。 - 在服务器块(server block)中添加以下配置: ```nginx server { listen 443 ssl; server_name your_domain.com; ssl_certificate /etc/nginx/ssl/your_certificate.crt; ssl_certificate_key /etc/nginx/ssl/your_private_key.key; # 其他配置项... } ``` 将`your_domain.com`替换为您的域名,将`your_certificate.crt`和`your_private_key.key`替换为您上传的证书文件的路径和名称。 4. 配置其他SSL选项(可选): - 您可以据需要添加其他SSL选项,例如启用严格的SSL协议、配置加密套件等。这些选项应该放在`server`块内的`ssl_certificate_key`配置项之后。 5. 保存并关闭配置文件。 6. 检查Nginx配置文件是否正确: - 运行以下命令检查Nginx配置文件是否有语法错误: ```bash nginx -t ``` - 如果配置文件没有错误,将显示`nginx: configuration file /etc/nginx/nginx.conf test is successful`。 7. 重新加载Nginx配置: - 运行以下命令重新加载Nginx配置: ```bash systemctl reload nginx ``` 8. 验证SSL证书安装: - 使用浏览器访问您的域名,确保能够通过HTTPS连接到您的网站,并且浏览器中显示证书已验证。 现在,您已成功在Linux上安装了SSL证书并配置了Nginx来使用它。请注意,此过程可能因您的操作系统和Nginx版本而有所不同,因此请据实际情况进行相应的调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值