How to Forward HTTP methods from apache2 using proxy_ajp to tomcat

浪尽此生 提交于 2020-04-30 06:38:47

问题


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:


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.



来源:https://stackoverflow.com/questions/61371633/how-to-forward-http-methods-from-apache2-using-proxy-ajp-to-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!