自签名证书主要用途还是用来测试,因为可以自签名那肯定就可以被仿冒,就会出现一些安全问题。 某些浏览器JS API必须在https才能够支持,这个时候就派上用场了。
创建私钥
会提示你输入一个口令,也就是所谓的密码
openssl genrsa -des3 -out xjh.key 1024
根据生成私钥去生成证书请求文件
会让你输入口令和一大堆信息,什么国家名字城市名字
openssl req -new -key xjh.key -out xjh.csr
去除口令
如果不去除口令每次restart都会让你输入
$ mv xjh.key test.key
$ openssl rsa -in test.key -out xjh.key
$ rm -rf test.key
最后使用这2个文件去生成crt文件
365也就是1年 可设置更长
openssl x509 -req -days 365 -in xjh.csr -signkey xjh.key -out xjh.crt
Nginx使用CA证书
在server添加就好了
server {
listen 9006;
server_name localhost;
ssl on;
ssl_certificate /Users/xiejiahe/Documents/cert/cert/xjh.crt;
ssl_certificate_key /Users/xiejiahe/Documents/cert/cert/xjh.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root /Users/xiejiahe/Documents/nginx/nginx/9006/;
index index.html;
}
}
访问
https://localhost:9006