内网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的配置方式

相关推荐
閞杺哋笨小孩29 分钟前
面向「机构按域名访问、同一套前端」的 Nginx 示例
nginx
源远流长jerry2 小时前
Linux 本机网络通信机制深度解析:Loopback 设备原理
linux·运维·服务器·网络·tcp/ip·nginx·负载均衡
落叶_Jim3 小时前
Let‘s Encrypt证书有效期缩短至90天后,如何实现自动续期
网络协议·https·ssl
spmcor6 小时前
一文搞定 Nginx 开机自启:Windows / Linux / macOS 全平台指南
nginx
fred_kang1 天前
Windows 下 Nginx 启动报错 10013 / OpenEvent 完整排查指南
运维·windows·nginx
imuliuliang1 天前
五大编程语言核心对比:特性与应用全解析
运维·spring boot·nginx
天草二十六_简村人1 天前
对接AI大模型之nginx代理配置SSE接口
运维·网络·nginx·http·阿里云·ai·云计算
小趴菜克鲁里1 天前
Cocos Creator 进阶:打造灵活可控的进度条动画组件(循环与分段)
运维·nginx
heimeiyingwang1 天前
【架构实战】Nginx七层负载均衡:从配置到原理,从入门到精通
nginx·架构·负载均衡
pengyi8710151 天前
安全性深度对比,HTTP与HTTPS代理风险差异分析
网络协议·http·https