How can I forward requests coming in on port 80 to another port on the same linux machine?

I used to do this by changing nat.conf, but this machine that I'm using doesn't have NAT. What's the alternative?

Thanks,

Nohsib

link|improve this question
Not enough information; this sounds like it belongs on serverfault. – Ex Umbris Oct 11 '11 at 22:36
No NAT whatsoever or just no nat.conf? Have you tried any iptables rules using NAT? – Ben Swinburne Oct 11 '11 at 22:38
feedback

migrated from stackoverflow.com Oct 11 '11 at 23:11

This question came from our site for professional and enthusiast programmers.

3 Answers

You can accomplish the redirection with iptables:

iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
link|improve this answer
+1. Being doing this for years – Alexander Pogrebnyak Oct 12 '11 at 0:33
feedback

You should look at using a reverse proxy, such as Nginx...

e.g. put this in your nginx.conf file:

server {
   listen         80;

   server_name    your_ip_address your_server_name

   access_log   /var/log/nginx/your_domain/access.log ;
   error_log    /var/log/nginx/your_domain/error.log info ;

   location / {
      proxy_pass  http://127.0.0.1:3000;   # pass requests for dynamic content to Rails app
   }
}
link|improve this answer
feedback

Rinetd setup is easier I think.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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