Linux下使用openssl生成SSL证书 供nginx使用

这里说下 系统怎么通过生成 证书。

 

首先执行如下命令生成一个4096位的key

openssl genrsa -des3 -out .key 4096
然后他会要求你输入这个key文件的密码。不推荐输入。因为以后要给nginx使用。每次reload nginx配置时候都要你验证这个PAM密码的。

 

由于生成时候必须输入密码。你可以输入后 再删掉

mv .key xxx.key
openssl rsa -in xxx.key -out hupohost.key
 -rm xxx.key

 

然后根据这个key文件生成证书请求文件

openssl req -new -key hupohost.key -out hupohost.csr
以上命令生成时候要填很多东西 一个个看着写吧(可以随便,毕竟这是自己生成的证书)

 

最后根据这2个文件生成证书文件

openssl x509 -req -days 3650 -in hupohost.csr -signkey hupohost.key -out hupohost.crt
这里3650是证书有效期 推荐3650哈哈。这个大家随意。最后使用到的文件是key和crt文件。

 

如果需要用pfx 可以用以下命令生成
openssl pkcs12 -export -inkey hupohost.key -in hupohost.crt -out hupohost.pfx

 

在需要使用证书的nginx配置文件的server节点里加入以下配置就可以了

ssl on;
ssl_certificate /home/hupohost.crt;
ssl_certificate_key /home/hupohost.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
然后重启nginx就大功告成了

 

最重要的是,访问是进行访问

server{
        listen 443;
        ssl on;
        ssl_certificate /usr/local/nginx/conf/vhost/ssl/hupohost.crt;
        ssl_certificate_key /usr/local/nginx/conf/vhost/ssl/hupohos.key;
}
端口一定是443端口
原文链接:https://yusky.me/under-linux-using-openssl-to-generate-the-ssl-certificate-for-the-use-of-nginx.html,转载请注明出处。
0

评论6

  1. 请问这个可以用在AMH上?
    alen 2016-03-01 0 回复
    • 可以,只是会报证书错误,毕竟这个自己生成的是不会受信任的。
      Yusky 2016-03-01 0 回复
      • 尝试过后,我决定放弃了。小站加个HTTPS也没必要
        alen 2016-03-01 0 回复
        • 哈。本来也没啥用。就是装逼用。
          Yusky 2016-03-04 0 回复
          • 相对有注册功能的还是安全一点。
            alen 2016-03-05 0 回复
没有账号?注册  忘记密码?