nginx创建证书

 

一、例如给test.imdst.com创建自签名证书

  • 创建根证书的私匙
    openssl genrsa -out test.imdst.com.key 2048

  • 利用私钥创建签名请求
    openssl req -new -subj "/C=US/ST=GuangDong/L=GuangZhou/O=Your Company Name/OU=imdst.com/CN=test.imdst.com" -key test.imdst.com.key -out test.imdst.com.csr
    说明:这里/C表示国家(Country),只能是国家字母缩写,如CN、US等;/ST表示州或者省(State/Provice);/L表示城市或者地区(Locality);/O表示组织名(Organization Name);/OU其他显示内容,一般会显示在颁发者这栏。

  • 将带口令的私钥移除
    mv test.imdst.com.key test.imdst.com.origin.key
    openssl rsa -in test.imdst.com.origin.key -out test.imdst.com.key

  • 用Key签名证书
    openssl x509 -req -days 3650 -in test.imdst.com.csr -signkey test.imdst.com.key -out test.imdst.com.crt

  • 为HTTPS准备的证书需要注意,创建的签名请求的CN必须与域名完全一致,否则无法通过浏览器验证

test.imdst.com.crt         自签名的证书  
test.imdst.com.csr         证书的请求  
test.imdst.com.key         不带口令的Key  
test.imdst.com.origin.key  带口令的Key  

二、nginx配置ssl验证

  • 把test.imdst.com.crt发给浏览器验证,然后用test.imdst.com.key解密浏览器发送的数据
  • nginx server {}配置
server  
{
        listen       443 ssl;
        server_name  test.imdst.com;
        ssl_certificate  test.imdst.com.crt; 
         ssl_certificate_key test.imdst.com.key;
       location = / {
            root   html;
        }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值