api - 我的 NGINX 反向代理不会将流量重新路由到外部虚拟机

标签 api ssl nginx tls1.2 nginx-reverse-proxy

我有两个虚拟机,在主机 Nginx 上,另一个也是独立服务器。 我将按如下方式调用虚拟机;

  • 独立 = 现金 服务 https
  • 托管 Nginx 的服务器= LOCAL serving http

为了让LOCALCASH通信,我们使用NGINX反向代理redirect HTTP 流量到 HTTPS 并处理 TLS 握手,以防 CASH调用 LOCAL NGINX 再次接受此 HTTPS 流量并将其重定向到 LOCALHTTP如图所示;

upstream  api_http_within_this_vm {
    server 127.0.0.1:9001;  #LOCAL VM caal it HOST VM application
}
#  SENDING HTTP TRAFFIC TO OUR HTTPS ENDPOINT Call CASH
server {
  listen 80;
  listen [::]:80;
  server_name         10.0.0.13;

  location / {
    proxy_pass  https://  api_https_to_another_vm;

    proxy_redirect     off;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    proxy_ssl_certificate     /etc/nginx/sites-available/signed_by_CASH.pem;
    proxy_ssl_certificate_key /etc/nginx/sites-available/local_key_used_to_generate_csr_for_CASH_to_sign.key;
    proxy_ssl_protocols       TLSv1.2;
    proxy_ssl_ciphers         HIGH:!aNULL:!MD5;
    proxy_ssl_trusted_certificate /etc/nginx/sites-available/CASH_CA.crt;

    proxy_ssl_verify       on;
    proxy_ssl_verify_depth 2;
    proxy_ssl_session_reuse on;
  }

}

upstream   api_https_to_another_vm {
  server 10.0.0.13:8080; # CASH's VM IP and PORT
}


#  RECIEVING HTTPS TRAFFIC ENDPOINT from CASH TO OUR LOCAL HTTP ENDPOINT 
server {
  listen 5555 ssl http2;
  listen [::]:5555 ssl http2;
  server_name         1270.0.0.1;

  location / {
    proxy_pass  http://api_http_within_this_vm;

    proxy_set_header X_CUSTOM_HEADER $http_x_custom_header;
    proxy_buffering    off;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   Host $http_host;
    proxy_pass_request_headers      on;
  }


  ssl_certificate     /etc/nginx/sites-available/signed_by_CASH.pem;
  ssl_certificate_key /etc/nginx/sites-available/local_key_used_to_generate_csr_for_CASH_to_sign.key;
  ssl_verify_client      off;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         HIGH:!aNULL:!MD5;
}

我的成功

  • CASHLOCAL 的流量运行良好。

我的挑战

  • LOCALCASH 的流量不起作用。当我直接使用 curl https://10.0.0.13:8080/ 而不使用 Reverse proxyLOCAL 时,我收到 502 Bad Request CASH 即使没有握手发生,我也会看到一些输出。

哪里不对,请指教.....

其次,Nginx 是否只将流量重定向到 VM 内的 IP,甚至重定向到其他 VM?

我主要想实现这种 leg这对我来说失败了。

最佳答案

随着时间的推移,我测试了这个配置,我不得不使用 tcpdump 进行跟踪,甚至检查了我的日志,因为我怀疑问题是由网络驱动的。我发现实际上客户端 CASH 在 TLS 握手完成之前断开了连接。

2019/03/02 06:54:58 [error] 27569#27569: *62 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: xx.xx.xx.xx, server: 1270.0.0.1, request: "GET / HTTP/1.1", upstream: "https://xx.xx.xx.xx:1000/", host: "xx.xx.xx.xx:80"

感谢所有观看者,但脚本是正确的。

关于api - 我的 NGINX 反向代理不会将流量重新路由到外部虚拟机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54944127/

相关文章:

java - 从没有 API 的网站获取数据?

javascript - 如何使用 JS SDK 检测从 fb 注销而不刷新页面

php - 加速 php api 调用

ruby-on-rails - 无法访问 RubyGems - 可能是由于 SSL?

windows - SSL 证书在刷新 Windows 服务器时消失

ubuntu - nginx 将非 www 重定向到 www 和 https

c# - 增加 Azure Api 应用程序中的最大请求长度

php - 使用 WordPress 通过 SMTP 发送邮件?

nginx - 如何从 http 响应头中删除 Nginx?

python - Django静态文件和nginx