Tomcat behind Apache behind Firewall: AJP ignores X-Forwarded-Proto -


we have following setup in case of https traffic:

  • firewall: terminates https, adds "x-forwarded-proto: https", forwards apache via http
  • apache: forwards tomcat through ajp
  • tomcat: receives request via ajp-connector

we have added remoteipvalve tomcat's server.xml:

<valve classname="org.apache.catalina.valves.remoteipvalve"                    remoteipheader="x-forwarded-for"                    protocolheader="x-forwarded-proto"             /> 

it works if skip apache , forward straight firewall tomcat regular http-connector. in case tomcat uses https redirect , base urls.

but once go through apache , ajp, x-forwarded-proto header seems ignored. checked, x-forwarded-proto header still present on tomcat's request.

i guess tomcat told through ajp front-end protocol used (http or https). maybe doesn't happen? need tell apache somehow consider x-forwarded-proto ajp?

apache virtualhost configuration:

<virtualhost *:80>     servername www.myserver.biz      jkmount /* loadbalancerhd </virtualhost> 

workers.properties:

worker.list=loadbalancerhd  worker.loadbalancerhd.balance_workers=hdnode1,hdnode2 worker.loadbalancerhd.type=lb worker.loadbalancerhd.sticky_session=true  worker.hdnode1.type=ajp13 worker.hdnode1.host=webserver01 worker.hdnode1.port=8010 worker.hdnode1.distance=0  worker.hdnode2.type=ajp13 worker.hdnode2.port=8010 worker.hdnode2.host=webserver02 worker.hdnode2.distance=1 

after studying mod_jk docs found out mod_jk evaluates apache environment variable https in order detect https. variable set mod_ssl if apache processes https traffic itself. not case since https terminated before apache.

simply setting environment variable based on http header trick:

setenvifnocase x-forwarded-proto https https=on 

btw: the environment variable evaluated mod_jk can changed jkhttpsindicator directive (see mod_jk docs). following same:

setenvifnocase x-forwarded-proto https external_traffic_is_https=on jkhttpsindicator external_traffic_is_https 

might useful if changing https interfere other modules.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -