Java System Properties
Quick Reference Guide


http.nonProxyHosts Java System Property

The http.nonProxyHosts java system property specifies a list of hosts that should be connected to directly, bypassing the HTTP and HTTPS proxy server.

Default Value

localhost|127.*|[::1]

The default value excludes the common variations of the loopback address, so that connections to the local machine are not sent through the proxy. Current OpenJDK source also includes 0.0.0.0 and [::0] in the default list.

Overview of http.nonProxyHosts

When a proxy server has been configured with the http.proxyHost or https.proxyHost system properties, all connections for that protocol are sent through the proxy. The http.nonProxyHosts system property lets you list hosts that should be reached directly instead, typically internal hosts.

There is no https.nonProxyHosts property: the HTTPS protocol handler uses the same http.nonProxyHosts list as the HTTP protocol handler. FTP uses its own ftp.nonProxyHosts property.

Value Format

In current OpenJDK versions, when you set http.nonProxyHosts to a non-empty value the default loopback patterns are appended to your list, so localhost will still bypass the proxy. Setting the property to an empty string removes all exclusions, including the loopback defaults.

Tip: Quote the value on the command line

The | character is the pipe operator in most shells, so be sure to wrap the value in quotes when passing it on the command line.

Example

java -Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=8080 -Dhttp.nonProxyHosts="localhost|*.example.com|192.168.*" -jar app.jar

In this example HTTP and HTTPS connections go through proxy.example.com:8080, except connections to localhost, any host in the example.com domain, or any 192.168.* IP address.

Related Properties

Other Networking System Properties

Here are some other networking Java system properties:

References

Supported Since

Java has supported the http.nonProxyHosts system property since at least Java 1.4.

Setting http.nonProxyHosts on Startup

You can set the http.nonProxyHosts java system property during startup of the java runtime using the -D command line argument:

java -Dhttp.nonProxyHosts=localhost|*.example.com MyAppMain

You may also be able to specify http.nonProxyHosts via the JAVA_TOOL_OPTIONS environment variable:

JAVA_TOOL_OPTIONS=-Dhttp.nonProxyHosts=localhost|*.example.com

Setting / Reading http.nonProxyHosts at Runtime

You can set http.nonProxyHosts at runtime with the following Java code:

System.setProperty("http.nonProxyHosts", "localhost|*.example.com");

WARNING: Depending on the property and JVM version using setProperty may or may not work if the JDK Java class that uses this variable has already been loaded. The value of the http.nonProxyHosts system property may be cached within an internal private static variable of the implementing class.

To read the value of http.nonProxyHosts at runtime, you can use this Java code:

String propertyValue = System.getProperty("http.nonProxyHosts");
if (propertyValue != null) {
    System.out.println("http.nonProxyHosts = " + propertyValue);
} else {
    System.out.println("http.nonProxyHosts was null");
}