Florian Ludewig
Florian Ludewig

Reputation: 6002

Redirect Port via iptables on AWS EC2 Ubuntu instance

I have a running AWS EC2 instance on an Ubuntu machine running a Nodejs server. Everything works fine then opening the website via its public ip on port 3000 likes this:

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

Now I want to redirect all requests from port 80 to this port 3000 via iptables like described in this video: 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.

Unfortunately I am getting this error: http://prntscr.com/lja6hx when opening the site like this: http://XX.XXX.XXX.XXX (without port 3000 specified)

P.S.: I'm not really sure if my approach is correct. I am open to other ways of achieving a redirect from port 80 (http) to port 3000


As @Vorsprung suggested I should use an Application Load Balancer. I did this but it's still not working. Here is my setup:

My Application Load Balancer Listener Application Load Balancer Listener

The Target Group I'm forwarding to in my ALB Target Group Description Target Group Targets

My hosted zone (I've added the alias for the ALB here) Hosted zone A record

Please let me know if something is missing

Upvotes: 2

Views: 1580

Answers (1)

Related Questions