Redirecting http to a different, internal host

I am using Apache 2.4.10 on Slackware64 14.1, kernel 3.10.17. I've used Apache for years and am *fairly* fluent, but have never "redirected". Need some help.

I have 2 hosts behind a firewall: 192.168.0.2 and 192.168.0.24. The 0.2 server has an external IP public domain name, e.g. mail.host.com. This server is running the Apache stated at top.

The 192.168.0.24 host is actually a video DVR and http://192.168.0.24 shows the various camera videos live. This box has no Internet connection.

What I want is for people accessing http://mail.host.com/DVR to be routed to the DVR host. The following in httpd.conf works:

Redirect /DVR http://192.168.0.24

but only inside the LAN. The reason being is that it only substitutes "http://192.168.0.24" into the client browser. That IP is not resolvable from outside the LAN.

How do I accomplish what I want?
LVL 1
MarkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael FowlerSolutions ConsultantCommented:
You want to look at setting up apache as a reverse proxy

Here is an example
http://www.jamescoyle.net/how-to/116-simple-apache-reverse-proxy-example

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarkAuthor Commented:
   <Location />
        ProxyPass http://mywebsite.jamescoyle.net/
        ProxyPassReverse http://mywebsite.jamescoyle.net/
        Order allow,deny
        Allow from all
    </Location>

Open in new window

Sorry, your link is not an understandable example for me. He is forwarding all www.jamescoyle.net to http://mywebsite.jamescoyle.net/. I want to route requests for  http://mail.host.com/DVR to http://192.168.0.24/. Other requests for http://mai.host.com need to be handled by that server. I don't get where the 'DVR' directory name goes in Mr. Coyle's example, ServerName? Do you have a different example? Meanwhile, I'll also search around.
MarkAuthor Commented:
OK, I found a solution: http://www.apachetutor.org/admin/reverseproxies. All I need is the following in httpd.conf:
ProxyPass /DVR/ http://192.168.0.24/

Open in new window

No need to configure VirtualHosts.

A final problem. Unless the user specifies a trailing '/' on DVR, I get a garbage screen. I've tried a 2nd ProxyPass line omitting the trailing slash:

ProxyPass /DVR http://192.168.0.24/

and a rewrite rule in $DOCUMENT_ROOT/.htaccess:

RewriteRule ^DVR$ DVR/ [R]

Neither work. Ideas?

http://www.apachetutor.org/admin/reverseproxies
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Michael FowlerSolutions ConsultantCommented:
Your rewrite rule looks fine. Have you made sure the rewrite module has been loaded and the engine turned on eg

LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine On
RewriteRule ^/DVR$ DVR/ [R]

http://www.dekho.com.au/help/32/default.htm?turl=Documents%2Fconfiguringapachehttpdforreverseproxy.htm
MarkAuthor Commented:
Your rewrite rule looks fine. Have you made sure the rewrite module has been loaded and the engine turned on ...
Yes, it is on. In fact I am using other rewrite rules. Perhaps one of two possible issues: 1) I did not specify a leading "/" and I also did not specify a RewriteBase, so I'll try it with the slash as you've shown. 2) perhaps the ProxyPass directive is processed before the rewrite rule in $DOCUMENT_ROOT/.htaccess? After the, the target web page is not really in $DOCUMENT_ROOT, so maybe in never looks there?

I can also try putting the rule in httpd.conf. I've never done that before, would it be the same anywhere in the "main" part of httpd.conf? :

RewriteEngine On
RewriteRule ^/DVR$ DVR/ [R]

Should I use the [R] flag or would [L] be more appropriate?

The [P] flag looks interesting http://httpd.apache.org/docs/current/rewrite/flags.html:
Use of the [P] flag causes the request to be handled by mod_proxy, and handled via a proxy request. For example, if you wanted all image requests to be handled by a back-end image server, you might do something like the following:

RewriteRule "/(.*)\.(jpg|gif|png)$" "http://images.example.com/$1.$2" [P]
MarkAuthor Commented:
Putting the following lines in httpd.conf did work:

RewriteEngine On
RewriteRule ^/DVR$ DVR/ [R]

Apparently those rules in .htaccess are not applied. Makes sense in a way because the target page is not in the $DOCUMENT_ROOT hierarchy.

Any thoughts on flags [R] versus [L] versus [P]?
Michael FowlerSolutions ConsultantCommented:
I have never really looked into this the flags but having a read it looks like the best option in this case would be the [P] flag as this rewrite is purely for the proxypass command.

Personally I would do a bit of testing but if I had to guess I think you would little or no difference between the flags in this implementation
MarkAuthor Commented:
Actually, the site  http://www.apachetutor.org/admin/reverseproxies recommended against using the [P] flag.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.