Nginx 配置SSL实现HTTPS访问
环境装备openSSL 需要安装并配置环境变量(记住安装位置)nginx 下载解压即可官网地址openSSL: Win32/Win64 OpenSSL Installer for Windows - Shining Light Productionsnginx: nginx: downloadopenSSL 环境变量配置新增系统变量变量名OPENSSL_HOME变量值D:\workspace\OpenSSL-Win64\bin(以自己实际安装路径为准)在path变量内新增内容%OPENSSL_HOME%nginx 配置在nginx安装目录下创建文件夹ssl在 ssl 文件夹下执行命令行操作创建私钥(输入密码时输入一个4位或更长):openssl genrsa -des3 -out yy.key 1024创建csr证书(输入密码后 一直回车即可)openssl req -new -key yy.key -out yy.csr复制文件copy yy.key yy.key.copy去除密码(输入上面设置的密码)openssl rsa -in yy.key.copy -out yy.key生成 crt 证书openssl x509 -req -days 365 -in yy.csr -signkey yy.key -out yy.crt有下面文件则说明证书生成完成配置 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; } }启动nginx 访问https 出现下面结果则说明配置成功

相关新闻

最新新闻

日新闻

周新闻

月新闻