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.

sorry for the title, but im such a newbie in server configurations. I have a problem (of course) and i will try my best to explain it to you:

  • I have a vps, debian based with apache2 and in it I have two domains configured with virtualhost.
  • the first domain is used to be the alias for a webserver (RUBY) and it is working with the port 8080
  • second one is a website, so it is supposed to be wotking with port 80, with apache2+mysql

My problem is that the webserver needs to redirect connections from port 80 to 8080, so my ruby developer (not me, I suck in ruby) made a redirect with

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

as a conseguence my website is not working with the port 80, of course. my question: is there a way to tell to iptables to redirect the port 80 only for the connection regarding the ruby server (and so, the first domain?) I cannot change the port of the server so how do you suggest me in order to use the 80 for the website? sorry for the silly questions but I totally suck in this. I forgot to mention that im not in contact with the ruby developer anymore, so this makes the things more dramatic to me :)

thanks in advance

share|improve this question
1  
Sounds to me like you're trying to do Level 7 stuff on Level 4 of the ISO model. –  Magellan Jul 31 '12 at 23:05
    
hmmm did I mention that I dont know almost anything about server configurations? :) –  Simone Jul 31 '12 at 23:07

1 Answer 1

If you're serving both domains from the same IP, you can't do this with port forwarding, because iptables has no way to know which domain the client is trying to connect to. Your server isn't involved in the DNS lookup, and the client doesn't send an HTTP Host: header until after the TCP connection has been established.

What you can do, though, is use Apache's mod_proxy to set up a reverse proxy that relays HTTP requests to the Ruby server. This recipe shows how:

<VirtualHost *:*>
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
    ServerName your.ruby.site
</VirtualHost>

With this configuration, people who visit the Ruby site won't actually be connecting to the Ruby server, they'll be connecting to Apache. But Apache will serve the pages by requesting them from the Ruby server, so the result is basically the same.

share|improve this answer
    
Thank you, ive been trying this solution with no luck (obviously there was something wrong), later I will try your configuration and let you know –  Simone Aug 1 '12 at 14:54
    
Unfortunately it is not working :( i tried also doing some rewriterule with a Redirect 301 to the .htaccess from the rubyserver, as i said the domain that is an alias for the ruby server is hosted elsewhere, and it is on the vps with a 301. –  Simone Aug 2 '12 at 14:08

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.