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

相关推荐
C_心欲无痕3 小时前
nginx - 实现域名跳转的几种方式
运维·前端·nginx
令狐少侠20117 小时前
docker基本操作 部署启动nginx
nginx·docker·容器
知南x7 小时前
【物联网视频监控系统----韦东山老师视频总结】(4)流媒体方案的实现之Nginx
物联网·nginx·音视频
守城小轩10 小时前
深度解析 Firefox 144+ 编译架构(四)源码拉取与环境引导全流程解析
firefox·浏览器自动化·指纹浏览器·浏览器开发
成为你的宁宁12 小时前
【Zabbix运维监控实战(附图文教程):Nginx 服务可用性、连接请求状态、CPU 内存占用与 JVM(Jar 包 / Tomcat)全维度监控】
运维·jvm·nginx·zabbix
游戏开发爱好者814 小时前
2025年iOS应用上架App Store全指南,开发者必看
android·ios·小程序·https·uni-app·iphone·webview
Htojk14 小时前
openssl签发自签名证书的流程
网络协议·https·ssl
oMcLin14 小时前
如何在 Debian 11 上配置并调优 Nginx 与 Lua 脚本,提升高流量 API 网关的性能与安全性?
nginx·debian·lua
oMcLin14 小时前
如何在CentOS 8.4上配置并优化Nginx负载均衡,确保跨境电商平台的高并发请求稳定处理?
nginx·centos·负载均衡
Hi2024021715 小时前
HTTPS流量分析-网关抓包与解密全解析
网络协议·http·https