Apache web server redirect post request

I have configured apache for 4 ports (with virtual hosts as some ports use HTTPS) and the goal is to redirect mail requests to different servlets running on a TOMCAT instance on some other machine. Calls are made using httpclient

(java client). When I start the client, it throws a 301 Error: moves permanently. Need hints / tips / help to solve this problem.

It would be nice if someone could give me an example. My virtual host (with redirection) looks something like this

<VirtualHost _default_:3334>
  RewriteEngine On
  RewriteRule ^/$ https://192.168.100.23:38443/Lang/Englangservices/Alapbhet_service
<\VirtualHost>

      


Now I can get the mod proxy working with mod rewrite and now I don't get the 302 error, but as always, another problem arises with the newbie.

HTTP POST requests are not working. When I issue a post request, the proxy fails as it keeps looking for index.htm.

My httpd.conf snippet

<VirtualHost *:3331>
  ServerName localhost:3331
  ProxyPass / http://192.168.100.23:38443/Lang/Englangservices/Alapbhet_service
  ProxyPassReverse / http://192.168.100.23:38443/Lang/Englangservices/Alapbhet_service
  RewriteEngine on
  RewriteRule ^/$ http://localhost:3331/
</VirtualHost>

      

0


source to share


4 answers


Achieved this with JK and mod rewrite. The problem was two-way SSL and I configured the ports to work in conjunction with port 443 (SSL).

i.e.

Note. If you want to rewrite the url on virtual hosts, then you need to reload JK-mount for each virtual host.



My url rewrites look like this

RewriteEngine on
RewriteCond% {SERVER_PORT} 4342
RewriteRule ^ / $ / Lang / Englangservices / Alapbhet_service [L, PT]

Thank you all for their input.

0


source


Another option that complements the already given mod _ proxy is mod _ jk. (sorry for the spaces, otherwise the formatting is messed up)

Both are apache extensions that allow apache to consume a request, transparently forward it to tomcat, wait for a response, and then send the result back.

IMHO mod_jk has several advantages

  • Tomcat automatically gets the serviced hostname, protocol and port (with mod_proxy you need to configure the fact that it is proxied in the connector, see the proxyName and ProxyPort parameters
  • mod_jk provides load balancing - if you need it
  • apache speaks to tomcat in the protocol designed for this task (ajp13). With mod_proxy, they're talking http, which has a slightly higher overhead (Disclosure: I've never measured this myself, just parroting it).


Which one you use in the end is entirely up to your choice - it doesn't really matter in either case. (Someone will fix me if this is the case)

The config looks like this (untested pseudocode. Read the docs, please understand what you are doing ...)

# somewhere in httpd.conf, above the virtual hosts
JkWorkersFile /etc/apache2/workers.properties
JkLogFile     /var/log/apache/mod_jk.log
JkLogLevel    error

# your existing part with virtual hosts
<VirtualHost ...>
   ....
   JkMount /Lang/* tomcat1
   JkMount /Lang   tomcat1  # if you need the directory itself also to be forwarded
   ....
</VirtualHost>

# the workers.properties file described above
# 'tomcat1' is the reference used above as argument to JkMount
workers.list=tomcat1
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1

      

+3


source


A 301 sounds like an appropriate answer if you really want to redirect, but perhaps you really wanted to proxy requests so the client doesn't know about the redirect? In this case, take a look at using mod_proxy as a reverse proxy.

+2


source


Your httpclient in java should handle 301 responses correctly. If it is not, it is violated. If you don't want to or can't, use mod_rewrite / mod_proxy , as Paul pointed out to "transparent" redirection, that's the way to go. See here

0


source







All Articles