首页 > 解决方案 > 如何让 Nginx 将 https 流量作为 https 代理服务器转发到上游?

问题描述

在这里,我想设置一个带有 nginx 作为负载均衡器的 Tor 集群,以提供 HA tor 服务。我选择“ https://github.com/reiz/nginx_proxy ” nginx 模块来提供 https_proxy 功能。它适用于 https 连接。但没有将 https 流量转发到上游。

发生了什么:

情况1:

当我运行下面的 cmd 时,它将从上游 tor 服务返回一个随机 ip,它适用于 http 流量。

curl -x localhost:8090 http://api.ipify.org

案例二:

它因 https 流量而失败,我可以从访问日志中看到

"CONNECT api.ipify.org:443 HTTP/1.1" 200 6176 "-" "curl/7.54.0" "-"

是的,作为 https 代理,nginx 可以工作,但无法将 https 流量转发到上游的 Tor。下面的命令总是返回相同的 ip,即我电脑的当前 ip。

curl -x localhost:8090 https://api.ipify.org

那么,我想要的是,如何让 nginx 将 https 流量转发到上游?

nginx.conf

user www-data;
worker_processes  auto;
daemon off;

events {}


http {

    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;
    error_log /var/log/nginx/error.log;
    include /usr/local/nginx/conf/conf.d/*.conf;
}

默认.conf

upstream torProxy {
    server tor-cluster_tor_1:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_2:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_3:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_4:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_5:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_6:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_7:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_8:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_9:8118 max_fails=3 fail_timeout=30s;
    server tor-cluster_tor_10:8118 max_fails=3 fail_timeout=30s;
}

server {
    listen      8090;
    proxy_connect;
    proxy_max_temp_file_size 0;
    resolver 8.8.8.8;
    location / {
        proxy_pass http://torProxy;
        proxy_set_header Host $http_host;
        proxy_set_header Authorization "";
    }
}

标签: nginxproxyload-balancingtor

解决方案


您可以使用 nginx 的流模块是一篇很好的文章,可以帮助您入门。


推荐阅读