How to configure OpenSource Apache Tomcat and Pivotal tc Server to use a Proxy server
search cancel

How to configure OpenSource Apache Tomcat and Pivotal tc Server to use a Proxy server

book

Article ID: 293332

calendar_today

Updated On:

Products

VMware Tanzu tc Server

Issue/Introduction

How to configure OpenSource Apache Tomcat and Pivotal tc Server to use a Proxy server by passing the Java http proxy properties to your Tomcat instance.

Environment


Resolution

If you are serving a web application behind a firewall that requires access through a proxy server (perhaps to access a service on the public internet), you can pass Java proxy properties to your Tomcat JVM server instance to allow your application to access the proxy server without the need of touching your application code.

Here's an example on how you can pass the following Java proxy properties to your favor of Tomcat JVM server instance:

Java Proxy Property Descriptions
 

http.proxyHost=proxy.server.com  # Specify the host name or IP address of the proxy server.
http.proxyPort=3128   # Specify the port number of the proxy server.
http.proxynonHost=localhost|host.mydomain.com|192.168.0  # Specify a list of hosts seperated by "|" that are not require access through the proxy server.

(For SSL proxy server, you need to use the HTTPS (HTTP over SSL) proxy properties)
 

https.proxyHost=proxy.server.com   # The host name or IP address of the SSL proxy server.
https.proxyPort=443  # The port number of the SSL proxy server.

You can add other proxy properties like http.proxyUser and http.proxyPassword depending on what's required by your proxy server for establishing a connection.  Please see Java documentation for more  Java Networking and Proxies  properties info.

Unix/Linux Pivotal tc Server

Add proxy properties to the "JVM_OPTS" line in vFTCS/tcs_instance/bin/setenv.sh:

JVM_OPTS="-Xmx512M -Xss192K -Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=3128 -Dhttp.proxynonHost=localhost|host.mydomain.com"

Windows Pivotal tc Server

For a Windows service, add proxy properties using the "wrapper.java.additonal.*" in vFTCS\tcs_instance\conf\wrapper.conf:
 

wrapper.java.additional.10="-Dhttp.proxyHost=proxy.server.com"
wrapper.java.additional.11="-Dhttp.proxyPort=3128"
wrapper.java.additional.12="-Dhttp.proxynonHost=localhost|host.mydomain.com"

Note that each "wrapper.java.additional.*" line is appended with a sequence incremental number.

Add proxy properties to the "set JVM_OPTS" line in vFTCS/tcs_instance/bin/setenv.bat:
 

set JVM_OPTS=-Xmx512M -Xss192K -Dhttp.proxyHost="proxy.server.com" -Dhttp.proxyPort="3128" -Dhttp.proxynonHost="localhost|host.mydomain.com"

Unix/Linux ASF Tomcat

Setup and export  the proxy properties  using  "JAVA_OPTS" environment variable in ASF_TOMCAT/bin/catalina.sh:
 

#!/bin/sh
JAVA_OPTS="-Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=3128 -Dhttp.proxynonHost=localhost|host.mydomain.com"; export JAVA_OPTS

To avoid the risk of losing any add on Java properties in catalina.sh due to Tomcat upgrade, consider exporting the Java properties in your own custom environment script or create one: I.E.   setenv.sh
 

JAVA_PROXY="-Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=3128  -Dhttp.proxynonHost=localhost|host.mydomain.com"
export JAVA_OPTS="$JAVA_PROXY ..."
...

A better a solution is to setup custom environment script with mutli-instance deployment layout.  FYI, see this kb article:  Installing Apache Tomcat 5.5/6/7 with a multi-instance layout on Linux

Windows ASF Tomcat

Setup proxy properties using  "JAVA_OPTS" environment variable in ASF_TOMCAT\bin\catalina.bat (For use in console mode):

rem  Java proxy properties for connecting to proxy server
set JAVA_OPTS=-Dhttp.proxyHost="proxy.server.com" -Dhttp.proxyPort="3128" -Dhttp.proxynonHost="localhost|host.domain.com"

To avoid the risk of losing any add on Java properties in catalina.sh due to Tomcat upgrade, consider exporting the Java properties in your own custom environment script or create one: I.E. setenv.bat
 

set JAVA_PROXY=-Dhttp.proxyHost=proxy.server.com -Dhttp.proxyPort=3128 -Dhttp.proxynonHost=localhost|host.mydomain.com
set JAVA_OPTS=%JAVA_PROXY% ...
...

If you are running Tomcat as NT service, use ASF_TOMCAT\bin\tomcat.exe command to add the proxy properties to the service name:
 

ASF_TOMCAT\bin\tomcat.exe //US//SERVICE_NAME ++JvmOptions "-Dhttp.proxyHost=proxy.vmware.com;-Dhttp.proxyPort=3128;-Dhttp.proxynonHost=localhost|host.domain.com"

Make sure to replace SERVICE_NAME with your tomcat service name.  For information on command line argument and parameter, please see the Tomcat Windows service how to documentation.

 

Additional Information

References:

Java Networking and Proxies - https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
Networking Properties - https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
Deployment Configuration File and Properties  - https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/properties.html
Apache Tomcat 8.0 Windows service HOW-TO - http://tomcat.apache.org/tomcat-8.0-doc/windows-service-howto.html