20

I have a web application running on Amazon EC2. It listens on port 9898.

I can access it by entering the ip address and port number.

e.g 1.2.3.4:9898

However, what I'd really like to be able to do is to not have to enter the port number.

Researching this, it looks like port forwarding might be the solution - i.e. forward http requests received on the default port (80) to my non-standard port (9898).

Is this the correct way to go? If so, how do I set this up on EC2?

If not, then how do I achieve what I want?

Thanks in advance for any help.

Update

I should have mentioned the EC2 instance is a Windows Server 2012 AMI.

ksl
  • 325

3 Answers3

10

The easiest way to do this without installing something yourself is putting an Amazon Elastic Load Balancer in front of the instance. These allow you to forward ports as you intend.

ceejayoz
  • 33,432
9

You have two options.

1) Set up a reverse proxy to forward the HTTP requests (assuming it's HTTP) to a different port.

It should be as simple as: Install apache, enable the proxy_http module, put something like:

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass / http://localhost:9898/
ProxyPassReverse / http://localhost:9898/

2) Set up IP Tables to forward the packets.

Tom O'Connor
  • 27,578
-3

because I saw the comment on using iptables, I'll share my experience in ec2 linux. I found an excellent article on forwarding ports for Node.js. If you skip to instructions on editing sysctl.conf you see the forwarding instructions. My Linux procedure varied from Ubuntu slightly. Article is: http://www.lauradhamilton.com/how-to-set-up-a-nodejs-web-server-on-amazon-ec2

The work is done via ssh. The only gotcha I ran into was I pre-routed twice, without flushing iptables between, and my web app was not visible until I flushed and reloaded. I know that's a terrible image to conclude with, sorry.

Brian
  • 21