📄 apacheconfig.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jk.config;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Hashtable;
import org.apache.catalina.Context;
import org.apache.catalina.Host;
/* The idea is to keep all configuration in server.xml and
the normal apache config files. We don't want people to
touch apache ( or IIS, NES ) config files unless they
want to and know what they're doing ( better than we do :-).
One nice feature ( if someone sends it ) would be to
also edit httpd.conf to add the include.
We'll generate a number of configuration files - this one
is trying to generate a native apache config file.
Some web.xml mappings do not "map" to server configuration - in
this case we need to fallback to forward all requests to tomcat.
Ajp14 will add to that the posibility to have tomcat and
apache on different machines, and many other improvements -
but this should also work for Ajp12, Ajp13 and Jni.
*/
/**
Generates automatic apache mod_jk configurations based on
the Tomcat server.xml settings and the war contexts
initialized during startup.
<p>
This config interceptor is enabled by inserting an ApacheConfig
<code>Listener</code> in
the server.xml file like so:
<pre>
* < Server ... >
* ...
* <Listener className=<b>org.apache.ajp.tomcat4.config.ApacheConfig</b>
* <i>options</i> />
* ...
* < /Server >
</pre>
where <i>options</i> can include any of the following attributes:
<ul>
<li><b>configHome</b> - default parent directory for the following paths.
If not set, this defaults to TOMCAT_HOME. Ignored
whenever any of the following paths is absolute.
</li>
<li><b>jkConfig</b> - path to use for writing Apache mod_jk conf file. If
not set, defaults to
"conf/auto/mod_jk.conf".</li>
<li><b>workersConfig</b> - path to workers.properties file used by
mod_jk. If not set, defaults to
"conf/jk/workers.properties".</li>
<li><b>modJk</b> - path to Apache mod_jk plugin file. If not set,
defaults to "modules/mod_jk.dll" on windows,
"modules/mod_jk.nlm" on netware, and
"libexec/mod_jk.so" everywhere else.</li>
<li><b>jkLog</b> - path to log file to be used by mod_jk.</li>
<li><b>jkDebug</b> - JK Loglevel setting. May be debug, info, error, or emerg.
If not set, defaults to emerg.</li>
<li><b>jkWorker</b> The desired worker. Must be set to one of the workers
defined in the workers.properties file. "ajp12", "ajp13"
or "inprocess" are the workers found in the default
workers.properties file. If not specified, defaults
to "ajp13" if an Ajp13Interceptor is in use, otherwise
it defaults to "ajp12".</li>
<li><b>forwardAll</b> - If true, forward all requests to Tomcat. This helps
insure that all the behavior configured in the web.xml
file functions correctly. If false, let Apache serve
static resources. The default is true.
Warning: When false, some configuration in
the web.xml may not be duplicated in Apache.
Review the mod_jk conf file to see what
configuration is actually being set in Apache.</li>
<li><b>noRoot</b> - If true, the root context is not mapped to
Tomcat. If false and forwardAll is true, all requests
to the root context are mapped to Tomcat. If false and
forwardAll is false, only JSP and servlets requests to
the root context are mapped to Tomcat. When false,
to correctly serve Tomcat's root context you must also
modify the DocumentRoot setting in Apache's httpd.conf
file to point to Tomcat's root context directory.
Otherwise some content, such as Apache's index.html,
will be served by Apache before mod_jk gets a chance
to claim the request and pass it to Tomcat.
The default is true.</li>
</ul>
<p>
@author Costin Manolache
@author Larry Isaacs
@author Mel Martinez
@author Bill Barker
*/
public class ApacheConfig extends BaseJkConfig {
private static org.apache.juli.logging.Log log =
org.apache.juli.logging.LogFactory.getLog(ApacheConfig.class);
/** default path to mod_jk .conf location */
public static final String MOD_JK_CONFIG = "conf/auto/mod_jk.conf";
/** default path to workers.properties file
This should be also auto-generated from server.xml.
*/
public static final String WORKERS_CONFIG = "conf/jk/workers.properties";
/** default mod_jk log file location */
public static final String JK_LOG_LOCATION = "logs/mod_jk.log";
/** default location of mod_jk Apache plug-in. */
public static final String MOD_JK;
//set up some defaults based on OS type
static{
String os = System.getProperty("os.name").toLowerCase();
if(os.indexOf("windows")>=0){
MOD_JK = "modules/mod_jk.dll";
}else if(os.indexOf("netware")>=0){
MOD_JK = "modules/mod_jk.nlm";
}else{
MOD_JK = "libexec/mod_jk.so";
}
}
private File jkConfig = null;
private File modJk = null;
// ssl settings
private boolean sslExtract=true;
private String sslHttpsIndicator="HTTPS";
private String sslSessionIndicator="SSL_SESSION_ID";
private String sslCipherIndicator="SSL_CIPHER";
private String sslCertsIndicator="SSL_CLIENT_CERT";
Hashtable NamedVirtualHosts=null;
public ApacheConfig() {
}
//-------------------- Properties --------------------
/**
set the path to the output file for the auto-generated
mod_jk configuration file. If this path is relative
then it will be resolved absolutely against
the getConfigHome() path.
<p>
@param path String path to a file
*/
public void setJkConfig(String path){
jkConfig= (path==null)?null:new File(path);
}
/**
set the path to the mod_jk Apache Module
@param path String path to a file
*/
public void setModJk(String path){
modJk=( path==null?null:new File(path));
}
/** By default mod_jk is configured to collect SSL information from
the apache environment and send it to the Tomcat workers. The
problem is that there are many SSL solutions for Apache and as
a result the environment variable names may change.
The following JK related SSL configureation
can be used to customize mod_jk's SSL behaviour.
Should mod_jk send SSL information to Tomact (default is On)
*/
public void setExtractSSL( boolean sslMode ) {
this.sslExtract=sslMode;
}
/** What is the indicator for SSL (default is HTTPS)
*/
public void setHttpsIndicator( String s ) {
sslHttpsIndicator=s;
}
/**What is the indicator for SSL session (default is SSL_SESSION_ID)
*/
public void setSessionIndicator( String s ) {
sslSessionIndicator=s;
}
/**What is the indicator for client SSL cipher suit (default is SSL_CIPHER)
*/
public void setCipherIndicator( String s ) {
sslCipherIndicator=s;
}
/** What is the indicator for the client SSL certificated(default
is SSL_CLIENT_CERT
*/
public void setCertsIndicator( String s ) {
sslCertsIndicator=s;
}
// -------------------- Initialize/guess defaults --------------------
/** Initialize defaults for properties that are not set
explicitely
*/
protected void initProperties() {
super.initProperties();
jkConfig= getConfigFile( jkConfig, configHome, MOD_JK_CONFIG);
workersConfig=getConfigFile( workersConfig, configHome,
WORKERS_CONFIG);
if( modJk == null )
modJk=new File(MOD_JK);
else
modJk=getConfigFile( modJk, configHome, MOD_JK );
jkLog=getConfigFile( jkLog, configHome, JK_LOG_LOCATION);
}
// -------------------- Generate config --------------------
protected PrintWriter getWriter() throws IOException {
String abJkConfig = jkConfig.getAbsolutePath();
return new PrintWriter(new FileWriter(abJkConfig, append));
}
// -------------------- Config sections --------------------
/** Generate the loadModule and general options
*/
protected boolean generateJkHead(PrintWriter mod_jk)
{
mod_jk.println("########## Auto generated on " + new Date() +
"##########" );
mod_jk.println();
// Fail if mod_jk not found, let the user know the problem
// instead of running into problems later.
if( ! modJk.exists() ) {
log.info( "mod_jk location: " + modJk );
log.info( "Make sure it is installed corectly or " +
" set the config location" );
log.info( "Using <Listener className=\""+getClass().getName()+"\" modJk=\"PATH_TO_MOD_JK.SO_OR_DLL\" />" );
}
// Verify the file exists !!
mod_jk.println("<IfModule !mod_jk.c>");
mod_jk.println(" LoadModule jk_module \""+
modJk.toString().replace('\\','/') +
"\"");
mod_jk.println("</IfModule>");
mod_jk.println();
// Fail if workers file not found, let the user know the problem
// instead of running into problems later.
if( ! workersConfig.exists() ) {
log.warn( "Can't find workers.properties at " + workersConfig );
log.warn( "Please install it in the default location or " +
" set the config location" );
log.warn( "Using <Listener className=\"" + getClass().getName() + "\" workersConfig=\"FULL_PATH\" />" );
return false;
}
mod_jk.println("JkWorkersFile \""
+ workersConfig.toString().replace('\\', '/')
+ "\"");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -