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;   #证书为服务器自带
相关推荐
475.351 小时前
linux-journal日志清理
linux·运维·服务器
Black__Jacket2 小时前
Ubuntu下,/dev下,无法读取到CH340串口芯片的端口号
linux·运维·ubuntu
小王不爱笑1322 小时前
云服务器部署 JavaWeb 项目
运维·服务器
清泉影月2 小时前
Linux:Squid正向代理实现内网访问互联网
linux·运维·服务器
霖霖总总2 小时前
[小技巧39]Linux 文件与命令查找工具(which、whereis、locate、find)全面解析
linux·运维
ayaya_mana2 小时前
在 CentOS 7/RHEL 7 上安装并切换至新版内核
linux·运维·centos
三不原则3 小时前
故障案例:数据库慢查询导致交易延迟,AIOps 如何自动定位?
运维·数据库
gzxx2007sddx3 小时前
ubuntu挂载访问windows的共享文件夹
linux·运维·ubuntu·挂载·共享
市安3 小时前
基于 LVS+Keepalived+NFS 的高可用 Web 集群构建与验证
运维·服务器·网络·lvs·keepalived·ipvsadm
AC赳赳老秦3 小时前
Dify工作流+DeepSeek:运维自动化闭环(数据采集→报告生成)
android·大数据·运维·数据库·人工智能·golang·deepseek