通过 AWS EC2 Ubuntu 实例上的 iptables 重定向端口

Redirect Port via iptables on AWS EC2 Ubuntu instance

我在 Ubuntu 机器 运行 Nodejs 服务器上有一个 运行 AWS EC2 实例。 一切正常,然后通过端口 3000 上的 public ip 打开网站,如下所示:

http://XX.XXX.XXX.XXX:3000

现在我想通过 iptables 将所有请求从端口 80 重定向到此端口 3000,如本视频中所述:https://www.youtube.com/watch?v=WxhFq64FQzA via

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000.

不幸的是,我收到此错误:http://prntscr.com/lja6hx 像这样打开网站时:http://XX.XXX.XXX.XXX(未指定端口 3000)

P.S.: 我不确定我的方法是否正确。我对实现从端口 80 (http) 到端口 3000

重定向的其他方法持开放态度

正如@Vorsprung 建议的那样,我应该使用 Application Load Balancer。我这样做了,但仍然无法正常工作。这是我的设置:

我的应用程序负载均衡器监听器

我在我的 ALB 中转发到的目标组

我的托管区域(我在此处添加了 ALB 的别名)

如有遗漏请告知

  1. 要么用nginx 看https://nodebb.readthedocs.io/en/latest/configuring/proxies/nginx.html
  2. 您正在使用 AWS!使用 ALB.. 参见 https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancer-tutorials.html