AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 583374
Accepted
Alex Flo
Alex Flo
Asked: 2014-03-21 03:18:39 +0800 CST2014-03-21 03:18:39 +0800 CST 2014-03-21 03:18:39 +0800 CST

将 Nginx 配置为具有上游 SSL 的反向代理

  • 772

我尝试将 Nginx 服务器配置为反向代理,以便它从客户端接收到的 https 请求也通过 https 转发到上游服务器。

这是我使用的配置:

http {

    # enable reverse proxy
    proxy_redirect              off;
    proxy_set_header            Host            $http_host;
    proxy_set_header            X-Real-IP       $remote_addr;
    proxy_set_header            X-Forwared-For  $proxy_add_x_forwarded_for;

    upstream streaming_example_com 
    {
          server WEBSERVER_IP:443; 
    }

    server 
    {
        listen      443 default ssl;
        server_name streaming.example.com;
        access_log  /tmp/nginx_reverse_access.log;
        error_log   /tmp/nginx_reverse_error.log;
        root        /usr/local/nginx/html;
        index       index.html;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_certificate /etc/nginx/ssl/example.com.crt;
        ssl_certificate_key /etc/nginx/ssl/example.com.key;
        ssl_verify_client off;
        ssl_protocols        SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers RC4:HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;


        location /
        {
            proxy_pass  https://streaming_example_com;
        }
    }
}

无论如何,当我尝试使用反向代理访问文件时,这是我在反向代理日志中遇到的错误:

2014/03/20 12:09:07 [错误] 4113079#0: *1 SSL_do_handshake() 失败(SSL:错误:1408E0F4:SSL 例程:SSL3_GET_MESSAGE:意外消息),同时 SSL 与上游握手,客户端:192.168.1.2,服务器:streaming.example.com,请求:“GET /publishers/0/645/_teaser.jpg HTTP/1.1”,上游:“ https://MYSERVER.COM:443/publishers/0/645/_teaser.jpg ” ,主机:“streaming.example.com”

知道我做错了什么吗?

nginx
  • 3 3 个回答
  • 105564 Views

3 个回答

  • Voted
  1. Best Answer
    Alex Flo
    2014-03-21T04:42:05+08:002014-03-21T04:42:05+08:00

    我发现是什么错误,我需要添加 proxy_ssl_session_reuse off;

    • 38
  2. iBug
    2019-06-03T09:47:30+08:002019-06-03T09:47:30+08:00

    就我而言,我试图反向代理 Cloudflare 背后的网站。我在/var/log/nginx/error.log. 我尝试了很多解决方案,这个对我有用:

    proxy_ssl_server_name on;
    

    请参阅nginx 文档:

    在与代理 HTTPS 服务器建立连接时,启用或禁用通过TLS 服务器名称指示扩展(SNI、RFC 6066)传递服务器名称。

    如果服务器首先使用服务器全局 TLS 证书终止 TLS 连接,它可以查看 HTTP Host 标头以确定哪个用户/应用程序应该接收 HTTP 请求。但是,如果服务器为具有不同 TLS 证书的域提供服务(Cloudflare 等所有 CDN 都这样做),则服务器需要知道要使用哪个 TLS 私钥来终止 TLS。因此它需要查看未加密的 TLS SNI 标头,因为 HTTP 主机标头仍然是加密的。

    • 27
  3. morganbaz
    2021-03-16T23:03:43+08:002021-03-16T23:03:43+08:00

    这完全解决了我的问题:

    location / {
        proxy_pass https://server2.example.com;
        proxy_set_header Host $host;
        proxy_ssl_name $host;
        proxy_ssl_server_name on;
        proxy_ssl_session_reuse off;
        ...
    }
    

    我还必须添加proxy_ssl_name以确保 nginx 知道要传递给上游 https 服务器的名称。

    • 1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve