18

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.

  • You'd need to have something in front of your server like HAProxy to forward requests..or use iptables. Amazon doesn't support port forwarding. – Nathan C Jan 24 '14 at 15:18
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.

| improve this answer | |
  • I tried your suggestion but I can't get the ping check to work. – ksl Jan 24 '14 at 19:27
  • ceejayoz is correct ELB is the way to do it. Use TCP check if HTTP is not working. Sorry not enough reputation to comment. – Pestouille Jan 24 '14 at 19:59
  • Hi, please can you elaborate. – ksl Jan 24 '14 at 20:11
  • Try allowing ICMP on the Windows Server Firewall from the ELB address(es) – Tom O'Connor Jan 24 '14 at 21:11
  • The firewall is already configured by default to allow all ICMP V4 traffic. – ksl Jan 27 '14 at 16:25
8

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.

| improve this answer | |
  • I should have stated that the EC2 instance is a Windows Server 2012 AMI. I haven't been able to figure out what the Windows equivalent of IP Tables is. – ksl Jan 24 '14 at 19:47
  • Thanks for the response. I tried using netsh as you suggested but I can't get it to work. I've forwarding http requests on port 80 to both the public and private ip addresses of my EC2 instance. – ksl Jan 27 '14 at 16:22
-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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.