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 / 问题 / 893783
Accepted
Arseni Mourzenko
Arseni Mourzenko
Asked: 2018-01-24 16:19:18 +0800 CST2018-01-24 16:19:18 +0800 CST 2018-01-24 16:19:18 +0800 CST

在 http 模式下访问代理服务器时如何启用 TLS?

  • 772

我使用 Nginx 服务器作为反向代理。它同时为 HTTP 和 HTTPS 流量提供服务,并将调用分派到多个仅支持 HTTP 的网站。

最近,我希望能够加密 Nginx 和底层服务器之间的流量。Nginx 仍然像以前一样解密它从 Internet 接收到的 HTTPS 流量,但随后应该使用带有不同证书的 HTTPS 来访问底层服务器。

我开始按照官方文档更改配置。但是,proxy_ssl on只能在一个stream级别内设置,而不能http。这可以通过nginx -twhich 显示包含proxy_ssl on;以下错误的行来确认:

此处不允许使用“proxy_ssl”指令 [...]

我的困难是我使用 Nginx 来记录流量、添加标题等,所以我必须使用http. 如果我的理解是正确的,那么stream当 Nginx 用于直接传输 HTTPS 流量时需要级别,没有解密它的能力(即 SSL Pass-thru),这不是我的情况。

我可以让 Nginx 通过 HTTPS 连接到底层服务器,同时仍然使用http级别及其所有好处,例如日志记录和更改标头吗?

当前配置:

http {
    proxy_set_header ... # Logging and custom headers.

    ...

    upstream demo-failover {
        server demo1.example.com:443 weight=1000 max_fails=0;
        server demo2.example.com:443 backup;
    }

    server {
        listen 80 proxy_protocol;
        listen 443 ssl http2 proxy_protocol;
        server_name demo.example.com;

        # HTTPS configuration for public exchange (Internet <-> Nginx).
        ssl_certificate /.../fullchain.pem;
        ssl_certificate_key /.../privkey.pem;

        ssl_stapling on;
        ssl_stapling_verify on;

        # HTTPS configuration for private exchange (Nginx <-> underlying server).
        proxy_ssl on; # This is the line which is invalid.
        proxy_ssl_trusted_certificate /.../ca.pem;
        proxy_ssl_certificate /.../demo.pem;
        proxy_ssl_certificate_key /.../demo.key;
        proxy_ssl_verify on;
        proxy_ssl_verify_depth 2;
        proxy_ssl_session_reuse on;

        if ($scheme = http) {
            return 301 https://$server_name$request_uri;
        }

        location / {
            proxy_pass http://demo-failover;
            proxy_next_upstream error timeout invalid_header;
            proxy_connect_timeout 2;
            proxy_redirect off;
            proxy_http_version 1.1;
        }
    }
}
nginx
  • 1 1 个回答
  • 2290 Views

1 个回答

  • Voted
  1. Best Answer
    Arseni Mourzenko
    2018-01-24T16:38:25+08:002018-01-24T16:38:25+08:00

    找到了。

    无需切换到stream,也无需使用proxy_ssl on。

    与官方文档不同的示例显示了如何在http级别上使用 HTTPS。诀窍(当我尝试删除proxy_ssl on并发现自己使用 Nginx 尝试使用 HTTP 调用底层服务器时,这是我的错误)是proxy_pass值。就我而言,我保留了原始值:

    proxy_pass http://demo-failover;
    

    相反,我应该将其更改为https:

    proxy_pass https://demo-failover;
    #              ^
    
    • 2

相关问题

  • 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