0

I'm trying to use apache as a proxy server to redirect some requests to a service running on a different port. I'm attempting to follow the instructions here: http://httpd.apache.org/docs/2.4/rewrite/proxy.html

I've done exactly this to install (and nothing else):

sudo apt-get install apache2
sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_http

Then edited /etc/apache2/httpd.conf to be:

RewriteEngine on
RewriteRule ^/(.*) http://localhost:9200/$1 [P]
ProxyPassReverse / http://localhost:9200/

Then finally, restarted apache2 (sudo service apache2 restart). Eventually, I'll add some real conditions to that rule, but I'm just trying to test it for now.

But it's not working. curl -XGET localhost:80/foo fails with a 404 response, curl -XGET loaclhost:9200/foo succeeds. Nothing useful in the error log or access log.

Joe K
  • 18,204
  • 2
  • 36
  • 58

1 Answers1

0

I would recommend setting your Apache reverse proxy commands to be something like this; note the ProxyPass setting as well as ProxyRequests and ProxyPreserveHost settings:

 <IfModule mod_proxy.c>

  # Proxy specific settings
  ProxyRequests Off
  ProxyPreserveHost On

  <Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass / http://localhost:9200/ 
  ProxyPassReverse / http://localhost:9200/ 

</IfModule>

I would also recommend you check the headers of the response output in curl by using the -I option like this:

curl -I localhost:80/foo

It should show you the exact response from the server so you can fully understand what might be failing and what might be working.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • Thanks - I guess I should add that the reason I'm trying to do it using the RewriteRule is because I might eventually be wanting some fairly complex RewriteConds, moreso than what seems possible with just ProxyPass. – Joe K Nov 11 '14 at 06:25
  • @JoeK You’re mixing the two issues up. The server itself—using the settings I have—will proxy all traffic to `http://localhost:9200/`. What you do with `mod_rewrite` is completely different and outside of that logic. – Giacomo1968 Nov 11 '14 at 06:27
  • Is there a way to use those settings but only forward specific request methods? Taking a step back - what I'm looking to do is proxy only GET requests, and only those to specific paths, and reject all others. I tried using settings like this, plus an additional rewrite rule, but it seemed like the proxy was happening before the rewrite. As an example, I added: `RewriteRule .* - [F]` but all requests still went through successfully. – Joe K Nov 11 '14 at 06:36
  • @JoeK Sorry, but what you are asking is pretty unfocused & not in line with your question. Feel free to edit your question to elaborate more specifically on what your goal is. But as for my answer? Done. If you feel this answer has helped you, please remember to up vote it. And if it is the answer that solved your question, please remember to check it off as such. – Giacomo1968 Nov 11 '14 at 07:04