LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-10-2004, 09:47 AM   #1
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
Apache: Forward request to another box?


Hello!

Is there a way I can forward a request for a domain to another box on my LAN? Here's the juice:
I have a Linksys router (WRT54G) which I port forward 80 to my Apache server. I have another box connected to this router that I also run Apache on, but want to host another/different domain (I know I can host the domain on the same server, but I want to know if I can do it on different boxes) on. I am wondering if there is an entry that I can place in my apache conf's to get this to work out, some sort of Vhost entry:
<VirtualHost 192.168.1.40>
</VirtualHost>

But I don't know if that's even correct. For examples sake, let's call my private IP's the following:
Main Server: 192.168.1.20
New Server hosting Apache for new domain: 192.168.1.40

Any suggestions welcome, and I just figured since this is likely *mostly* related to networking (although it would certainly have also fit in several other forums) I'd post it here. Feel free to move it accordingly

Cool

Oh yes, forgot to mention I do not want to run on different service ports.

Thanks!

Last edited by MasterC; 12-10-2004 at 09:48 AM.
 
Old 12-10-2004, 11:05 AM   #2
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 46
main server (192.168.1.20)

Code:
<VirtualHost *:80>
        ServerName www.whatever.com
        RewriteEngine     On
        RewriteRule       ^(.*)$        http://192.168.1.40$1  [P]
</VirtualHost>
Then set up a vhost on 192.168.1.40 that does the actual hosting for www.whatever.com. That should do it.
 
Old 12-11-2004, 12:40 AM   #3
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Original Poster
Rep: Reputation: 64
Awesome, thanks! Will give it a try right now.

Cool
 
Old 12-11-2004, 02:23 AM   #4
kola
Member
 
Registered: Jul 2004
Location: Christchurch, New Zealand
Distribution: FC2, Debian 'Sarge'
Posts: 64

Rep: Reputation: 15
Quote:
Originally posted by sigsegv
main server (192.168.1.20)

Code:
<VirtualHost *:80>
        ServerName www.whatever.com
        RewriteEngine     On
        RewriteRule       ^(.*)$        http://192.168.1.40$1  [P]
</VirtualHost>

Then set up a vhost on 192.168.1.40 that does the actual hosting for www.whatever.com. That should do it.
Hi sigsegv.

Is it possible to forward like this, but to the same machine, just on a different port? Then have apache ignore what happens to it?
 
Old 12-11-2004, 03:32 AM   #5
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Original Poster
Rep: Reputation: 64
It works perfect, thanks!

Cool
 
Old 12-11-2004, 09:07 AM   #6
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 46
Quote:
Originally posted by kola
Hi sigsegv.

Is it possible to forward like this, but to the same machine, just on a different port? Then have apache ignore what happens to it?
I guess so, though I'm not really sure why you'd want to. If you have multiple server instances on the same physical box, you should probably be doing name based VirtualHosts (And no, you *can't* use this to bypass the multiple SSL certs on a single IP/port problem)

To answer your question, your rewrite would look like:
Code:
RewriteRule       ^(.*)$        http://192.168.1.40:8080$1  [P]
Replace 8080 with your port number of course.
 
Old 12-11-2004, 02:11 PM   #7
kola
Member
 
Registered: Jul 2004
Location: Christchurch, New Zealand
Distribution: FC2, Debian 'Sarge'
Posts: 64

Rep: Reputation: 15
Yay, finally it works. I'd already tried what you posted and had no luck. Now i just found that if i include mod_proxy_http it works ok. Silly me!

Quote:
Originally posted by sigsegv
I guess so, though I'm not really sure why you'd want to. If you have multiple server instances on the same physical box, you should probably be doing name based VirtualHosts (And no, you *can't* use this to bypass the multiple SSL certs on a single IP/port problem)
I kinda thought i was using name based vhosts, i guess i got mixed up then somewhere. No idea about the SSL thing though, lol. Thats way above my head.

cheers
lee
 
Old 12-11-2004, 03:53 PM   #8
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 46
Quote:
Originally posted by kola
I kinda thought i was using name based vhosts, i guess i got mixed up then somewhere. No idea about the SSL thing though, lol. Thats way above my head.
Perhaps I should approach this another way -- Why do you have Apache listening on more than one port on the same server?
 
Old 12-11-2004, 04:11 PM   #9
kola
Member
 
Registered: Jul 2004
Location: Christchurch, New Zealand
Distribution: FC2, Debian 'Sarge'
Posts: 64

Rep: Reputation: 15
Quote:
Originally posted by sigsegv
Perhaps I should approach this another way -- Why do you have Apache listening on more than one port on the same server?
Ah, I dont. I have apache running once, but another httpd (custom) is also running for another purpose. So apache should serve any requests to the normal pages (mydomain.com) and pass anything for otherdomain.com to the other httpd on a different port.
When i learn more about php, SSI and CGI i will probably get apache to handle everything, but until then this is the best way to keep my pages working.

That make sense?

So far i have this, which seems to work. But there might be a better/more secure way to do it.

Code:
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Listen 80
ServerName mydomain.com

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /usr/local/apache2/htdocs
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ErrorLog logs/mydomain.com-error_log
    CustomLog logs/mydomain.com-access_log common
<VirtualHost *:80>
    ServerName otherdomain.com
    ServerAlias www.otherdomain.com
    RewriteEngine     On
    RewriteRule       ^(.*)$       http://localhost:5678$1  [P]
</VirtualHost>
 
Old 09-28-2007, 12:15 AM   #10
papayiya
LQ Newbie
 
Registered: Jan 2007
Posts: 3

Rep: Reputation: 0
Hi sigsegv,

Thank you for posting this. Is here anyway to attach in the rewrite URL the fact that this request is for whatever . com? Cause the way it is now, the second server (I think) will not know that this request is for whatever . com.

Thanks,
George
 
Old 10-26-2007, 04:27 PM   #11
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 46
George;

If I understand your question correctly I believe this is what you're looking for:

Code:
<VirtualHost *:80>
        ServerName www.whatever.com
        RewriteEngine     On
        RewriteRule       ^(.*)$        http://www.whatever.com$1  [P]
</VirtualHost>
Now ... This will get interesting because the webserver that this lives on will have to have a host file entry for 'www.whatever.com'. If the webserver looked up www.whatever.com through DNS it would get it's own IP address back (assuming it uses the internet to resolve the domain and not a local DNS server). Most of the time when you're using Apache as a transparent proxy it's just to one server with one domain being served on it.

I wrote this in a hurry. I hope it makes senses and helps answer your question.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache 2: forward http to https? OneSeventeen Linux - Software 2 07-03-2006 07:10 AM
How2 let apache2 forward the request to another web-server on another machine boomy Linux - Software 9 12-04-2005 03:50 PM
struggling to port forward apache 1.3 dynamicsamurai Linux - Networking 1 06-15-2005 01:40 AM
Dual-homed Box won't forward packets meadensi Linux - Networking 2 02-19-2005 02:04 PM
apache, port-forward and router on same box quickbeam Linux - Networking 2 05-14-2002 08:54 AM


All times are GMT -5. The time now is 02:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration