How to Forward HTTP methods from apache2 using proxy_ajp to tomcat

327 views Asked by At

I have configured and web server with apache2 then proxy request to tomcat with ajp protocol like this:

<host *:443>

        ProxyRequests On
        ProxyPreserveHost On
        <Proxy *>
          Order allow,deny
          Allow from all
          AllowMethods GET PUT DELETE POST OPTIONS
        </Proxy>
        ProxyPass / ajp://some_vhost:8009/
        ProxyPassReverse / ajp://some_vhost:8009/

All request received from apache2 server forward to GET HTTP method to tomcat, so if you are listening for some rest operation a post method this behavior causes a non supported method.

so, i would like to know how to forward the original HTTP request method to the tomcat container through AJP connector

Actual scenario: client -> POST req Apache2 -> GET method to apache tomcat. What i want client -> POST req Apache2 -> POST method to apache tomcat.

Thanks in advance!

UPDATE.

I have a rewrite condition on the vhost listening in port 80 which rewrite to https

RewriteEngine on
        RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
        RewriteCond %{SERVER_NAME} =mydomain.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

How can i rewrite the Http Methods too?? I think this is the issue, because when I launch the request with https: it works

1

There are 1 answers

0
Mark Thomas On

Your analysis is incorrect. httpd always forwards the original HTTP method to Tomcat via the AJP protocol.

The issue is the HTTPS redirect. When the original POST is redirected, the client is responding with a GET. You want to issue a 307 redirect, not a 301.

Note: My (probably dated) experience is that clients don't always response correctly to a 307.