8

This seems straightforward, but I can't make it work.

I have a pretty trivial webserver that only needs to do two things:

  1. example.com/status.html returns a local file (this works)
  2. example.com/atom redirects the contents of the firewalled server running on the same machine on port 4000

This didn't work:

RewriteRule ^$ http://localhost:4000

That redirected traffic back to localhost:4000 from the requestor's point of view (ie, on the client's machine).

My limited understanding of VirtualHost indicates that that's for something like atom.example.com, not example.com/atom

I think I have to use ProxyReverse, but I can't find the right combination.

UPDATE: Trying the ProxyPass/ProxyReverse suggestion given by Shane Madden produces this in the error log file:

[Thu Mar 15 11:59:15 2012] [error] (13)Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1:4000 (localhost) failed
[Thu Mar 15 11:59:15 2012] [error] ap_proxy_connect_backend disabling worker for (localhost)
[Thu Mar 15 11:59:17 2012] [error] proxy: HTTP: disabled connection for (localhost)

(The local server is definitely running on 127.0.0.1:4000)

Steve Bennett
  • 5,539
  • 12
  • 45
  • 57

1 Answers1

9

Don't use mod_rewrite unless you have a reason to do so.

Try this (put it in the <VirtualHost> block):

ProxyPass /atom http://127.0.0.1:4000/atom
ProxyPassReverse /atom http://127.0.0.1:4000/atom
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • At the moment I don't have a virtualhost block - will I need one? Or two? And if so, do they both start "VirtualHost *:80"? – Steve Bennett Mar 15 '12 at 00:48
  • Are you sure you don't have one? Most sets of default configuration files do define one; how'd you install Apache? But - if you do not have one, then there's no need to add one - just add these directives to the server context. – Shane Madden Mar 15 '12 at 00:51
  • Ok that didn't quite work: "service temporarily unavailable" for /atom (/blah returns 404 so it's doing something...) – Steve Bennett Mar 15 '12 at 00:54
  • Shane: that section of httpd.conf only contains the commented out examples – Steve Bennett Mar 15 '12 at 00:56
  • Also, I think I installed it with yum install httpd – Steve Bennett Mar 15 '12 at 00:56
  • That means that the service that Apache's trying to proxy to isn't responding. Is the service on port 4000 listening and correctly responding? – Shane Madden Mar 15 '12 at 00:58
  • If you installed with yum, then there's likely a file containing active vhosts in `/etc/httpd/conf.d/`. – Shane Madden Mar 15 '12 at 00:59
  • (there are 7 conf files in conf.d but none contain virtualhosts) – Steve Bennett Mar 15 '12 at 01:06
  • Hmm, here's a thought. The atom server takes nearly 10 seconds to generate and return the feed. Is it possible Apache is giving up too soon? – Steve Bennett Mar 15 '12 at 01:08
  • 3
    Finally works. I needed to change a security setting: sudo /usr/sbin/setsebool -P httpd_can_network_connect 1 – Steve Bennett Mar 15 '12 at 01:24
  • P.S. if you will forward the root '/' don't forget The '/' at the end is important other wise you get an error when browsing sub folder or files... The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /folder – Shereef Marzouk Feb 01 '13 at 18:06