Wiki source code of Configure Tomcat to Find Proxy Headers
Last modified by Eleni Cojocariu on 2026/11/25 19:37
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | Behind a [[reverse proxy>>doc:documentation.xs.admin.installation.http-reverse-proxy.WebHome]], every request reaches Tomcat from the proxy over plain ##HTTP##, so that is what Tomcat reports: the proxy's address as the client address, and ##http## as the protocol. Tomcat's ##RemoteIpValve## makes it read the headers the proxy adds instead, and report what the reader actually sent. XWiki does not depend on it, since it reads those same headers itself when it builds URLs, but everything that asks the container rather than XWiki does: Tomcat's own access log, and any code calling ##getRemoteAddr##, ##getScheme## or ##isSecure##. | ||
| 2 | |||
| 3 | 1. Set up a reverse proxy that sends the forwarded headers, following [[Configure Apache HTTP Server as a Proxy on a Linux OS>>doc:documentation.xs.admin.installation.http-reverse-proxy.apache-key-configurations.configure-apache-server-linux.WebHome]] or [[Set up NginX Proxy Server>>doc:documentation.xs.admin.installation.http-reverse-proxy.nginx-key-configurations.configure-nginx-server-linux.WebHome]]. | ||
| 4 | 1. Open the ##TOMCAT_HOME/conf/server.xml## file. | ||
| 5 | 1. Add the valve directly inside the ##Engine## element:((( | ||
| 6 | {{code language="xml"}} | ||
| 7 | <Engine name="Catalina" defaultHost="localhost"> | ||
| 8 | |||
| 9 | <Valve className="org.apache.catalina.valves.RemoteIpValve" /> | ||
| 10 | |||
| 11 | </Engine> | ||
| 12 | {{/code}} | ||
| 13 | ))) | ||
| 14 | 1. If the proxy runs on another machine, add an ##internalProxies## attribute that its address matches, for example {{code language="none"}}internalProxies="203\.0\.113\.7"{{/code}}. The value replaces the default, which covers the loopback and the private address ranges and is why the valve above needs nothing when the proxy sits on the same host, so the expression has to match every proxy the wiki is served through. Tomcat 10.1 reads the attribute as a regular expression; Tomcat 11 also accepts a list of CIDR blocks, for example {{code language="none"}}internalProxies="203.0.113.7/32"{{/code}}, and deprecates the regular expression form. | ||
| 15 | 1. Add ##requestAttributesEnabled="true"## to the ##AccessLogValve## element of the host, further down the same file, so that the access log uses what the valve found rather than the connection the request arrived on. This is the one place the attribute has to be written out: it defaults to ##false## there and to ##true## on the valve above. | ||
| 16 | 1. Restart Tomcat. | ||
| 17 | 1. Open a wiki page through the proxy. In the access log under ##TOMCAT_HOME/logs/##, for example ##localhost_access_log.2026-08-17.txt##, the first field of that request is now the reader's address instead of the proxy's, and the wiki keeps generating the links it already generated. |