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 / 问题 / 1075851
Accepted
Trigus
Trigus
Asked: 2021-08-28 15:12:53 +0800 CST2021-08-28 15:12:53 +0800 CST 2021-08-28 15:12:53 +0800 CST

完全透明的反向代理

  • 772

我正在尝试设置以下内容:

┌──────────────────┐            ┌────────────────────┐           ┌─────────┐    
│                  │            │                    │           │         │    
│      Router      │            │                    │           │Server 1 │    
│       NAT        │Port forward│                    │           │         │    
│                  │ ────────►  │     Server 0       │           │HTTP >   │    
│                  │            │                    │           │HTTPS    │    
│                  │            │    1.example.com  ───────────► │redirect │    
│                  │            │    2.example.com  ────┐        └─────────┘    
└──────────────────┘            └────────────────────┘  │         192.168.178.8 
                                     192.168.178.4      │                       
                                                        │   ┌─────────┐         
                                                        │   │         │         
                                                        │   │         │         
                                                        │   │Server 2 │         
                                                        └─► │         │         
                                                            │HTTP only│         
                                                            │         │         
                                                            └─────────┘         
                                                            192.168.178.7       

我希望服务器 0 充当仅转发流量的完全透明代理。这样客户端就不会与服务器 0 建立 TLS 连接,而是直接与服务器 1/2 建立连接,并且在服务器 1/2 上基于 HTTP-01 挑战的自动证书生成和更新仍然有效。

subdomain ssl nginx reverse-proxy transparent-proxy
  • 1 1 个回答
  • 796 Views

1 个回答

  • Voted
  1. Best Answer
    Trigus
    2021-08-30T10:06:20+08:002021-08-30T10:06:20+08:00

    编辑:如果您担心反向代理(终止 SSL 隧道)和内容服务器之间的连接不安全,尽管这确实有效并且是安全的,但您最好配置上游 SSL 或安全隧道,如 SSH 或内容服务器和反向代理之间的 IPSEC。


    我让它工作:

    文件结构:

    ngnix/
        config/
            nginx.conf
        http_server_name.js
        docker-compose.yml
    

    nginx.conf

    load_module modules/ngx_stream_js_module.so;
    
    events {}
    
    stream {
        js_import main from http_server_name.js;
        js_set $preread_server_name main.get_server_name;
    
        map $preread_server_name $http {
            1.example.com server1_backend_http;
            2.example.com server2_backend_http;
        }
    
        map $ssl_preread_server_name $https {
            1.example.com server1_backend_https;
            2.example.com server2_backend_https;
        }
    
        upstream server1_backend_http {
            server 192.168.178.8:80;
        }
        
        upstream server1_backend_https {
            server 192.168.178.8:443;
        }
    
        upstream server2_backend_http {
            server 192.168.178.7:80;
        }
    
        server {
            listen 443;  
            ssl_preread on;
            proxy_pass $https;
        }
    
        server {
            listen 80;
            js_preread main.read_server_name;
            proxy_pass $http;
        }
    }
    

    码头工人-compose.yml

    version: '3'
    
    services:
      ngnix:
        image: nginx
        container_name: ngnix
        restart: unless-stopped
        volumes:
          - ./config/ngnix.conf:/etc/nginx/nginx.conf:ro
          - ./config/http_server_name.js:/etc/nginx/http_server_name.js:ro
        ports:
          - "192.168.178.4:80:80"
          - "192.168.178.4:443:443"
    

    http_server_name.js

    var server_name = '-';
    
    /**
     * Read the server name from the HTTP stream.
     *
     * @param s
     *   Stream.
     */
    function read_server_name(s) {
      s.on('upload', function (data, flags) {
        if (data.length || flags.last) {
          s.done();
        }
    
        // If we can find the Host header.
        var n = data.indexOf('\r\nHost: ');
        if (n != -1) {
          // Determine the start of the Host header value and of the next header.
          var start_host = n + 8;
          var next_header = data.indexOf('\r\n', start_host);
    
          // Extract the Host header value.
          server_name = data.substr(start_host, next_header - start_host);
    
          // Remove the port if given.
          var port_start = server_name.indexOf(':');
          if (port_start != -1) {
            server_name = server_name.substr(0, port_start);
          }
        }
      });
    }
    
    function get_server_name(s) {
      return server_name;
    }
    
    export default {read_server_name, get_server_name}
    

    文档:
    ngx_http_upstream_module
    ngx_http_map_module
    ngx_stream_proxy_module

    编辑:
    阅读这篇博文了解更多信息

    • 1

相关问题

  • Apache 上的子域不工作 - 找不到服务器

  • 如何使用域经销商 API 设置域屏蔽?

  • 如何在 IIS7 中创建子域?

  • 通配符 DNS 和子域

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