建立私有CA及Nginx绑定SSL加密

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了建立私有CA及Nginx绑定SSL加密相关的知识,希望对你有一定的参考价值。

生成CA私钥

[[email protected] ~]#cd /etc/pki/CA/ ---------------进入CA目录
[[email protected] CA]#(umask 077; openssl genrsa -out private/ca.key 2048)----------生成私钥,可以生成2048或者1024位

Generating RSA private key, 2048 bit long modulus
..............................................................+++
..........................+++
e is 65537 (0x10001)

生成 CA 的证书

[[email protected] CA]#openssl req -new -x509 -key private/ca.key -out cacert.crt -days 3650

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) []:BJ      ##你所在的省份
Locality Name (eg, city) [Default City]: BJ    ##你所在的城市
Organization Name (eg, company) [Default Company Ltd]: maiya   ##你的组织机构名(公司名)
Organizational Unit Name (eg, section) []: jiaoxue
Common Name (eg, your name or your server‘s hostname) []: ca.maiya.com    ##域名
Email Address []:

生成nginx 的私钥、申请文件、CA颁发证书

生成Nginx私钥:

[[email protected] ~]#cd /etc/nginx/
[[email protected] nginx]#mkdir ssl
[[email protected] nginx]#cd ssl/
[[email protected] ssl]# (umask 077; openssl genrsa -out nginx.key 2048)

Generating RSA private key, 2048 bit long modulus
............+++
.................................................+++
e is 65537 (0x10001)

[[email protected] ssl]# ls ---------------------生成nginx私钥
nginx.key

生成申请文件

[[email protected] ssl]# openssl req -new -key nginx.key -out nginx.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) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:maiya
Organizational Unit Name (eg, section) []:jiaoxue
Common Name (eg, your name or your server‘s hostname) []:web.maiya.com
Email Address []:
Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

[[email protected] ssl]# ls
nginx.csr nginx.key

向CA提交申请文件

[[email protected] ssl]# cp nginx.csr /etc/pki/CA/

CA颁发证书

[[email protected] ssl]# cd /etc/pki/CA/
[[email protected] CA]# openssl ca -in nginx.csr -out nginx.crt -days 365

将证书绑定在Nginx上

在nginx的配置文件添加如下内容:

server {
listen 443 ssl http2 default_server;
server_name web.maiya.com;
root /usr/share/nginx/html;
ssl_certificate "/etc/nginx/ssl/nginx.crt";
ssl_certificate_key "/etc/nginx/ssl/nginx.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
}

以上是关于建立私有CA及Nginx绑定SSL加密的主要内容,如果未能解决你的问题,请参考以下文章

创建私有CA, 加密解密基础, PKI, SSL

Linux学习笔记—— 基于CentOS创建私有CA及应用

SSL及使用openssl实现CA

SSL基础知识及Nginx/Tomcat配置SSL

利用openssl建立私有CA

利用openssl建立私有CA