内网nginx配置Https证书

生成CA根证书

生成CA私钥

shell 复制代码
openssl genrsa -out ca.key 2048

生成CA根证书

shell 复制代码
openssl req -x509 -new -nodes -key ca.key -sha256 -days 1024 -out ca.crt

为内网IP生成私钥和证书请求文件(CSR)

生成内外 IP 的私钥

shell 复制代码
openssl genrsa -out server.key 2048

使用私钥生成证书请求文件

shell 复制代码
openssl req -new -key server.key -out server.csr

填写内容与上述CA一致,最后两行直接回车跳过

创建证书扩展文件

为了确保为 内网IP 签名的证书能够用作服务器身份验证,需要为它创建一个扩展文件。创建一个名为 v3.ext 的文件,并添加以下内容

复制代码
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment 
subjectAltName = @alt_names
 
[alt_names]
#这里 IP 替换成 DNS 就可以签名域名了 
IP.1 = 192.168.140.120

使用 CA 的证书为内网 IP 签名证书

shell 复制代码
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext

部署Nginx

对于nginx 来说,这里得到了 server.crt 和 server.key 就已经可以了对于nginx 来说,这里得到了 server.crt 和 server.key 就已经可以了

复制代码
server {
        listen       443 ssl;
        server_name  localhost;
        
        #ssl证书
        ssl_certificate ../../server.crt; 
        #私钥文件
        ssl_certificate_key ../../server.key; 
        ssl_session_cache shared:SSL:1m;                 
        ssl_session_timeout 5m;
        ssl_ciphers HIGH:!aNULL:!MD5; 
        ssl_prefer_server_ciphers on;
       
 
        location / {
            root   html;
            index  index.html index.htm;
        }
}
  • 其中 .../.../server.crt和.../.../server.key两个文件需要放入到/etc/nginx文件夹下,否则nginx读不到,可以写绝对路径

参考https://blog.csdn.net/cmy768330962/article/details/134380663

上述参考还有tomcat的配置方式

相关推荐
matlab的学徒4 小时前
nginx+springboot+redis+mysql+elfk
linux·spring boot·redis·nginx
00后程序员张4 小时前
苹果软件混淆的工程逻辑,从符号空间到资源扰动的体系化实现
android·ios·小程序·https·uni-app·iphone·webview
coder4_14 小时前
OpenSSL 加密算法与证书管理全解析:从基础到私有 CA 实战
https·openssl·ssl/tls·加密算法·ca证书
vortex518 小时前
解决 Kali 中 Firefox 下载语言包和插件速度慢的问题:配置国内镜像加速
前端·firefox·腾讯云
NicolasCage1 天前
解决苍穹外卖WebSocket连接失败的问题
nginx
维尔切1 天前
Nginx 反向代理与负载均衡
运维·nginx·负载均衡
IT_Octopus1 天前
https私人证书 PKIX path building failed 报错解决
java·spring boot·网络协议·https
艾菜籽1 天前
网络原理-HTTPS
网络·网络协议·https
程序员三明治2 天前
HTTPS 真的牢不可破吗?—— 中间人攻击与安全机制解析
网络协议·安全·https
2501_915106322 天前
CDN 可以实现 HTTPS 吗?实战要点、部署模式与真机验证流程
网络协议·http·ios·小程序·https·uni-app·iphone