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.

I'm running CentOS on 3 servers. Server A runs my apache web server. Server B and C run other servers on different ports. I'm trying to get htt://serverA/math/ to proxy to htt://serverB:8765/ but I'm getting errors I can't seem to fix. Here is my entry into the httpd.conf file:

RewriteEngine On
RewriteRule ^math/(.*)$ http://serverB:8765/$1 [P]

I get the following error in my log:

[error] [client xx.xx.xx.xx] File does not exist: /var/www/html/math

If I change the httpd.conf to this:

RewriteEngine On
RewriteRule ^/(.*)$ http://serverB:8765/$1 [P]

All traffic to server A is redirected properly to server B, so I know that mod_rewrite and mod_proxy are working.

Can anyone point me in the right direction? Thanks.

share|improve this question
    
the p's were removed from the http's in order to post fewer than one hyperlink, per severfaults policy –  dw.emplod Jun 23 '09 at 22:16
add comment

3 Answers

I think your rule should be:

RewriteRule ^/math/(.*)$ http://serverB:8765/$1 [P]

Since it's not matched, you get the error messages

share|improve this answer
    
I've tried this, but it doesn't seem to proxy properly. The page loads, but all of the images are lost and and links point to the wrong place. –  dw.emplod Jun 23 '09 at 22:50
    
If images have absolute path (like /images/something.png), you will get problems because it will try to load image on ServerA. you have to use relative path or add /math/ in absolute path. –  radius Jun 23 '09 at 23:00
    
The best practice would be to do RewriteRule ^/math/(.*)$ serverB:8765/math/$1 [P] and put everything in /math/ on serverB, so that links will work in every case. When connecting through serverA and when reaching directly serverB –  radius Jun 23 '09 at 23:02
    
The site running on ServerB I have very little control over other than port, and it does seem to be using absolute paths. Are thare any other ways to deal with this? –  dw.emplod Jun 23 '09 at 23:07
    
What kind of url are not loading ? do you have logs on ServerA ? –  radius Jun 24 '09 at 20:26
add comment

katriel is right but you could also use the ProxyPass/ProxyPassReverse directive. See this. It's design to do what you want in a much simple way.
Example:

ProxyPass /math/ http://serverB:8765/
ProxyPassReverse /math/ http://serverB:8765/
share|improve this answer
    
This gives me the same problem as his. –  dw.emplod Jun 23 '09 at 23:06
add comment

radius is right--you're better off using the actual proxy directives. Something like this should work:

<Location /math>
    ProxyPass http://serverB:8765/
    ProxyPassReverse http://serverB:8765/
</Location>

The error that you're getting may be because you're proxying ".../math/" but not ".../math".

share|improve this answer
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.