Nginx 配置SSL实现HTTPS访问

环境装备

openSSL 需要安装并配置环境变量(记住安装位置)

nginx 下载解压即可

openSSL 环境变量配置

  • 新增系统变量:变量名 OPENSSL_HOME 变量值 D:\workspace\OpenSSL-Win64\bin(以自己实际安装路径为准)
  • 在path变量内新增内容 %OPENSSL_HOME%

nginx 配置

  • 在nginx安装目录下创建文件夹 ssl
  • 在 ssl 文件夹下执行命令行操作
  1. 创建私钥(输入密码时 输入一个 4位或更长 ): openssl genrsa -des3 -out yy.key 1024

  2. 创建csr证书(输入密码后 一直回车即可):openssl req -new -key yy.key -out yy.csr

  3. 复制文件: copy yy.key yy.key.copy

  4. 去除密码(输入上面设置的密码): openssl rsa -in yy.key.copy -out yy.key

  5. 生成 crt 证书:openssl x509 -req -days 365 -in yy.csr -signkey yy.key -out yy.crt

  6. 有下面文件则说明证书生成完成

  7. 配置 nginx 配置文件

    复制代码
    	server {
    		listen 8443 ssl;
    		server_name localhost;  # 替换为您的域名或IP
    		
    		ssl_certificate ./ssl/yy.crt;  
    		ssl_certificate_key ./ssl/yy.key;
    		
    		# SSL配置建议
    		ssl_protocols TLSv1.2 TLSv1.3;
    		ssl_ciphers HIGH:!aNULL:!MD5;
    		
    		location / {
    			root html;
    			index index.html index.htm;
    		}
    		 # 代理后端 API(关键配置)
    		location /admin-api/ {
    			# 将请求转发到后端服务器
    			proxy_pass http://localhost:8080/admin-api/;
    			
    			# 传递原始请求信息
    			proxy_set_header Host $host;
    			proxy_set_header X-Real-IP $remote_addr;
    			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    			proxy_set_header X-Forwarded-Proto $scheme;
    			
    			# 处理重定向
    			proxy_redirect off;
    			
    			# 超时设置
    			proxy_connect_timeout 60s;
    			proxy_send_timeout 60s;
    			proxy_read_timeout 60s;
    		}
    		
    	}
  8. 启动nginx 访问https 出现下面结果则说明配置成功

相关推荐
2501_915909061 天前
IPA 深度混淆是什么意思?从混淆强度到实际效果的解读
android·ios·小程序·https·uni-app·iphone·webview
全栈前端老曹1 天前
【MongoDB】安全与权限管理 —— 用户认证、角色权限、SSL 加密
前端·javascript·数据库·安全·mongodb·nosql·ssl
章老师说2 天前
NGINX官方谈Lua风险:这其实是两条网关技术路线之争
运维·nginx·负载均衡·lua·openresty
xixingzhe22 天前
SpringBoot + Nginx 免鉴权接口安全防护方案
运维·nginx·安全
HelloWorld工程师3 天前
新手如何快速申请SSL通配符证书...
网络协议·https·ssl
酷炫的水壶3 天前
使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制
运维·nginx·缓存
姚不倒3 天前
F5 SSL Profile 证书卸载深入篇
运维·网络协议·负载均衡·ssl·f5
智商偏低3 天前
Windows Nginx 完整安装 + 启动教程
运维·nginx
oscar9993 天前
3.4 Nginx 负载均衡——动态再平衡的反人性纪律
nginx·github·负载均衡·财富源代码