Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
No NAT whatsoever or just no nat.conf? Have you tried any iptables rules using NAT? –  Ben Swinburne Oct 11 '11 at 22:38
add comment

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
share|improve this answer
    
+1. Being doing this for years –  Alexander Pogrebnyak Oct 12 '11 at 0:33
1  
How about on Windows Server? –  Luc Aug 26 '12 at 21:26
add comment

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
   }
}
share|improve this answer
add comment

Rinetd setup is easier I think.

share|improve this answer
    
You saved me from pulling out the last of my hair. +1 –  Beachhouse May 20 '13 at 18:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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