社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  NGINX

如何将nginx tcp pass-through与ssl预读取和反向代理功能结合起来?

R. Moser • 4 年前 • 392 次点击  

我正在尝试设置一个nginx,whitch可以根据域名,将加密的tcp流传递给另一个应用程序,或者充当提供自己证书的反向代理。

我想归档以下情况:

 https://app1.app.com ──► pass-through encrypted tcp to :10001
 https://app2.app.com ──► pass-through encrypted tcp to :10002
 https://app3.app.com ──► serve ssl, reverse-proxy to http://ip:10003

因此,在不中断应用程序1和2的加密连接的情况下,nginx应该转发tcp数据包。证书将由申请者自行送达。主机名检测与ssl_preread一起工作。

但是应用程序3只能通过http访问,因此nginx应该为证书本身提供服务,并代理来自特定主机名的所有内容 app3.app.com 到未加密的后端。

我有一个前两种情况的工作配置,可以设置第三种情况,但无法找出如何在单个nginx配置中组合这两种情况。

到目前为止我所拥有的:

user www-data;
worker_processes  1;

load_module /usr/lib/nginx/modules/ngx_stream_module.so;

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
}

stream {
    map $ssl_preread_server_name $name {
        app1.app.de app1;
        app2.app.de app2;
        default default;
    }

    upstream app1 {
        server 127.0.0.1:10001 max_fails=3 fail_timeout=10s;
    }

    upstream app2 {
        server 127.0.0.1:10002 max_fails=3 fail_timeout=10s;
    }

    server {
        listen 8080;
        proxy_pass $name;
        ssl_preread on;
    }
}

如果有人能指点我正确的方向,我将不胜感激!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52635
 
392 次点击