自签SSL证书
- key 私钥 = 明文--自己生成(genrsa )
- csr 公钥 = 由私钥生成
- crt 证书 = 公钥 + 签名(自签名或者由CA签名)
生成私钥
需要输入密码两次 12345678 (随便输)
| openssl genrsa -des3 -out server.pass.key 2048 |
生成私钥 server.key
输入上面的密码
| openssl rsa -in server.pass.key -out server.key |
创建公钥
| openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=Beijing/L=Beijing/O=dev/OU=dev/CN=127.0.0.1" |
生成证书
days 后面指定天数
| openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt |
查看证书
| openssl x509 -in server.crt -noout -text |
nginx 配置
- 将
server.crt
和 server.key
文件拷贝之 nginx 下创建 ssl 文件中,如下配置重启 nginx 即可
- 安装Nginx时使用了
–with-http_ssl_module
参数(Linux)
| server { |
| listen 443 ssl ; |
| ssl_certificate "D:/dev/nginx/ssl/server.crt"; |
| ssl_certificate_key "D:/dev/nginx/ssl/server.key"; |
| |
| location / { |
| } |
| |
| error_page 404 /404.html; |
| location = /40x.html { |
| } |
| |
| error_page 500 502 503 504 /50x.html; |
| location = /50x.html { |
| } |
| } |
扩展信息
- 公用名称 (Common Name) 简称:CN 字段,对于 SSL 证书,一般为网站域名或IP地址;而对于代码签名证书则为申请单位名称;而对于客户端证书则为证书申请者的姓名;
- 单位名称 (Organization Name) :简称:O 字段,对于 SSL 证书,一般为网站域名;而对于代码签名证书则为申请单位名称;而对于客户端单位证书则为证书申请者所在单位名称;
- 组织单位 (organizational unit):简称:OU 字段 同上
证书申请单位所在地:
- 所在城市 (Locality) 简称:L 字段
- 所在省份 (State/Provice) 简称:S 字段
- 所在国家 (Country) 简称:C 字段,只能是国家字母缩写,如中国:CN
在线生成工具 https://myssl.com/csr_create.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库