LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Apache: Forward request to another box? (https://www.linuxquestions.org/questions/linux-networking-3/apache-forward-request-to-another-box-264864/)

MasterC 12-10-2004 09:47 AM

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!

sigsegv 12-10-2004 11:05 AM

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.

MasterC 12-11-2004 12:40 AM

Awesome, thanks! Will give it a try right now.

Cool

kola 12-11-2004 02:23 AM

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?

MasterC 12-11-2004 03:32 AM

It works perfect, thanks!

Cool

sigsegv 12-11-2004 09:07 AM

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.

kola 12-11-2004 02:11 PM

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

sigsegv 12-11-2004 03:53 PM

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?

kola 12-11-2004 04:11 PM

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>


papayiya 09-28-2007 12:15 AM

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

sigsegv 10-26-2007 04:27 PM

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.

iammrbt 12-23-2014 09:37 PM

almost there!
 
I know this thread is old but hopefully still followed.

My problem is that I'm using a Virtual Server to server another page that's running a linux apache.

The physical server runs windows server (serves fine) VMware running ubuntu server

Using your rewrite help I successfully (sort of) server requests to the virtual server. The problem is that in changing the domain to an ip address when serving pages from outside the network. Obviously from within the network it works just fine.

So from the outside world when I go to the domain it serves the initial page just fine but all links are now 192.168.1.41/whatever

Is there anyway to make that rewrite 2 directional so that when the virtual server sends info back it does so as the domain that I'm entering?

I greatly appreciate your help


Update: Nevermind!

The problem was with the virtual machines wordpress install having the loopback address for its domain in the settings. After giving wordpress the domain name to use instead everything works just fine. Leaving this pot here in case someone else needs it. Thanks again for your help


All times are GMT -5. The time now is 09:48 PM.