Elastic Beanstalk 如何在没有 nginx/apache 的情况下将端口 80 上的流量转发到端口 8080 上的应用程序?

Ela*_*ava 3 networking amazon-web-services elastic-beanstalk

这是有史以来最奇怪的事情。我已将我的 AWS Elastic Beanstalk 环境的代理服务器设置配置为none而不是 nginx 或 apache,以减少服务器开销,并且因为我不需要缓存。

然而,最奇葩的事情发生了。服务器能够接受端口 80 上的连接并将它们转发到我在 8080 上运行的 Node.js 应用程序,即使显然没有服务在端口 80 上侦听!我使用以下命令进行了验证:

  • sudo lsof -i :80 - 没有输出
  • sudo iptables -L - 没有转发规则
  • sudo netstat -an | grep :80 | grep LISTEN - 没有进程侦听端口 80

curl http://localhost/在实际服务器上运行是有效的,因此这不是棘手的 Elastic Load Balancer 转发规则的情况。

AWS 是如何做到的?他们如何在没有进程监听:80或 iptables 转发规则的情况下转发流量?

Ela*_*ava 8

这是 NAT 规则。

iptables -L -t nat

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination    
Run Code Online (Sandbox Code Playgroud)

感谢来自 reddit 的@slims_s