Nginx端到端反向代理https配置

bash 复制代码
客户端(用户) --HTTPS--> Nginx --HTTPS--> 上游服务器

完整配置

bash 复制代码
# 上游服务器定义
upstream https_backend {
    server backend1.example.com:443 weight=3;
    server backend2.example.com:443 weight=2;
    keepalive 32;
}

# HTTPS 服务器块
server {
    listen 443 ssl http2;
    server_name proxy.example.com;
    
    # 前端 SSL 配置
    ssl_certificate /etc/ssl/certs/proxy.example.com.crt;
    ssl_certificate_key /etc/ssl/private/proxy.example.com.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
    
    # 安全头
    add_header Strict-Transport-Security "max-age=31536000" always;
    
    location / {
        # 基本代理设置
        proxy_pass https://https_backend;
        
        # SSL 端到端配置
        proxy_ssl_verify on; 
        proxy_ssl_trusted_certificate /etc/ssl/certs/ca-bundle.crt;
        proxy_ssl_verify_depth 2;
        proxy_ssl_server_name on; 
        proxy_ssl_name 后端服务域名;
        proxy_ssl_session_reuse on;
        
        # 请求头设置
        proxy_set_header Host $proxy_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_connect_timeout 5s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
        
        # 缓冲设置
        proxy_buffering on;
        proxy_buffer_size 4k;
        proxy_buffers 8 4k;
        
        # HTTP 1.1 保持连接SSE流式传输
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        chunked_transfer_encoding off;
        
        # 错误处理
        proxy_next_upstream error timeout invalid_header;
        proxy_next_upstream_tries 2;
    }
    
    # 健康检查
    location /health {
        access_log off;
        proxy_pass https://https_backend/health;
        proxy_ssl_verify off;
    }
}
bash 复制代码
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-bundle.crt;   #证书为服务器自带
相关推荐
Cosolar1 小时前
LlamaIndex索引类型全解析:原理与实战指南
运维·服务器
方便面不加香菜4 小时前
Linux--基础IO(一)
linux·运维·服务器
鼎讯信通6 小时前
风电光缆运维提质增效:G-4000A 光缆故障追踪仪破解风场巡检难题
运维·网络·数据库
三十..6 小时前
MySQL 从入门到高可用架构实战精要
运维·数据库·mysql
跨境数据猎手7 小时前
大数据在电商行业的应用
大数据·运维·爬虫
linyanRPA8 小时前
影刀RPA店群自动化实战:多店铺活动自动报名与促销管理架构设计
运维·自动化·办公自动化·rpa·python脚本·爬虫自动化·店群自动化
会Tk矩阵群控的小木8 小时前
安卓群控系统对于游戏工作室实战教程
android·运维·游戏·adb·开源软件·个人开发
o0麦嘎9 小时前
内网ip配置https
网络协议·tcp/ip·https
佛山个人技术开发9 小时前
GitCode SSH连接配置教程
运维·ssh·gitcode
OpsEye10 小时前
系统负载高一定是CPU问题吗?
运维·cpu·it