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

相关推荐
Knight_AL5 小时前
Docker 中的端口映射原理:为什么 Nginx 要 `listen 80`,而不是“随便写端口”
nginx·docker·容器
虹梦未来7 小时前
【运维心得】Ubuntu2404编译nginx隐藏Server信息
运维·服务器·nginx
00后程序员张10 小时前
AppStoreInfo.plist 在苹果上架流程中的生成方式和作用
android·小程序·https·uni-app·iphone·webview
tgethe11 小时前
Nginx笔记
运维·笔记·nginx
游戏开发爱好者811 小时前
对 iOS IPA 文件进行深度混淆的一种实现路径
android·ios·小程序·https·uni-app·iphone·webview
invicinble12 小时前
对于nginx(一,认识nginx)
运维·nginx
徒手千行代码无bug12 小时前
Nginx upstream 负载均衡 404,单节点转发正常的根因与解决
运维·nginx·负载均衡
张人玉12 小时前
WPF HTTPS 通信示例代码分析笔记
笔记·https·wpf
吃喝不愁霸王餐APP开发者12 小时前
Java应用对接美团开放平台API时的HTTPS双向认证与证书管理实践
java·开发语言·https
irisart12 小时前
第二章【NGINX 开源功能】—— 七层反向代理(下)
运维·nginx