Chinaunix首页 | 论坛 | 博客
  • 博客访问: 136789
  • 博文数量: 31
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 318
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-24 22:10
个人简介

2011.4 ~ 2015.7 就职于百度运维部,负责百度推广后台系统运维; 2015.7至今,就职于北京屏芯科技(互联网+餐饮),负责稳定性、安全、敏捷、速度等工作。

文章分类

全部博文(31)

文章存档

2016年(4)

2015年(27)

我的朋友

分类: 网络与安全

2015-12-15 15:59:18

科普: 
openssl中有如下后缀名的文件
.key格式:私有的密钥
.csr格式:证书签名请求(证书请求文件),含有公钥信息,certificate signing request的缩写
.crt格式:证书文件,certificate的缩写
.crl格式:证书吊销列表,Certificate Revocation List的缩写
.pem格式:用于导出,导入证书时候的证书的格式,有证书开头,结尾的格式 

登录任意一台linux机器,生成自制证书

点击(此处)折叠或打开

  1. $ openssl genrsa -des3 -out server.key 2048
  2. Enter pass phrase for server.key: 输入你的密码短语

  3. $ openssl req -new -key server.key -out server.csr
  4. Enter pass phrase for server.key: 输入你的密码短语
  5. You are about to be asked to enter information that will be incorporated
  6. into your certificate request.
  7. What you are about to enter is what is called a Distinguished Name or a DN.
  8. There are quite a few fields but you can leave some blank
  9. For some fields there will be a default value,
  10. If you enter '.', the field will be left blank.
  11. -----
  12. Country Name (2 letter code) [XX]:CN
  13. State or Province Name (full name) []: 省份
  14. Locality Name (eg, city) [Default City]: 城市
  15. Organization Name (eg, company) [Default Company Ltd]: 公司名称
  16. Organizational Unit Name (eg, section) []: 组织名称
  17. Common Name (eg, your name or your server's hostname) []: 待加密的网址
  18. Email Address []: 管理员邮箱, 如果你要申请正式CA颁发的证书,请填写whois的注册邮箱

  19. Please enter the following 'extra' attribute
  20. to be sent with your certificate request
    A challenge password []: 密码,最好只是数字与大小写字母的组合
    An optional company name []: 

    $ mv server.key server.key.orignal
    # 下面的命令,避免在启动nginx的时候输入密码短语
    $ openssl rsa -in server.key.orignal -out server.key
    Enter pass phrase for server.key.orignal: 输入最开始的密码短语
    writing RSA key


    $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    Signature ok

    $ ll
    total 16
    -rw-rw-r-- 1 work work 1375 Aug 25 17:46 server.crt
    -rw-rw-r-- 1 work work 1139 Aug 25 17:44 server.csr
    -rw-rw-r-- 1 work work 1679 Aug 25 17:46 server.key
    -rw-rw-r-- 1 work work 1751 Aug 25 17:37 server.key.orignal 

最终我们需要的是server.crt 和 server.key, 最好把它们重命名为你的网址对应的crt和key,方便区分。

nginx配置

点击(此处)折叠或打开

  1. server {
  2.         listen 8000;
  3.         server_name 你的域名;

  4.         rewrite ^(.*) https://$server_name$1 permanent;
  5.     }
  6. # 省略其他的配置
  7. server {
  8.     listen 8443;
  9.     server_name 你的域名;

  10.     ssl on;
  11.     ssl_certificate /home/work/nginx/https/server.crt;
  12.     ssl_certificate_key /home/work/nginx/https/server.key;
  13.         
  14.     location / {
  15.         # 省略
  16.     }

参考:


阅读(1573) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~