📄 apacheconfig.java
字号:
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( "Can't find workers.properties at " + workersConfig ); log( "Please install it in the default location or " + " set the config location" ); log( "Using <Listener className=\"" + getClass().getName() + "\" workersConfig=\"FULL_PATH\" />" ); return false; } mod_jk.println("JkWorkersFile \"" + workersConfig.toString().replace('\\', '/') + "\""); mod_jk.println("JkLogFile \"" + jkLog.toString().replace('\\', '/') + "\""); mod_jk.println(); if( jkDebug != null ) { mod_jk.println("JkLogLevel " + jkDebug); mod_jk.println(); } return true; } protected void generateVhostHead(Host host, PrintWriter mod_jk) { mod_jk.println(); String vhostip = host.getName(); String vhost = vhostip; int ppos = vhost.indexOf(":"); if(ppos >= 0) vhost = vhost.substring(0,ppos); mod_jk.println("<VirtualHost "+ vhostip + ">"); mod_jk.println(" ServerName " + vhost ); String [] aliases=host.findAliases(); if( aliases.length > 0 ) { mod_jk.print(" ServerAlias " ); for( int ii=0; ii < aliases.length ; ii++) { mod_jk.print( aliases[ii] + " " ); } mod_jk.println(); } indent=" "; } protected void generateVhostTail(Host host, PrintWriter mod_jk) { mod_jk.println("</VirtualHost>"); indent=""; } protected void generateSSLConfig(PrintWriter mod_jk) { if( ! sslExtract ) { mod_jk.println("JkExtractSSL Off"); } if( ! "HTTPS".equalsIgnoreCase( sslHttpsIndicator ) ) { mod_jk.println("JkHTTPSIndicator " + sslHttpsIndicator); } if( ! "SSL_SESSION_ID".equalsIgnoreCase( sslSessionIndicator )) { mod_jk.println("JkSESSIONIndicator " + sslSessionIndicator); } if( ! "SSL_CIPHER".equalsIgnoreCase( sslCipherIndicator )) { mod_jk.println("JkCIPHERIndicator " + sslCipherIndicator); } if( ! "SSL_CLIENT_CERT".equalsIgnoreCase( sslCertsIndicator )) { mod_jk.println("JkCERTSIndicator " + sslCertsIndicator); } mod_jk.println(); } // -------------------- Forward all mode -------------------- String indent=""; /** Forward all requests for a context to tomcat. The default. */ protected void generateStupidMappings(Context context, PrintWriter mod_jk ) { String ctxPath = context.getPath(); if(ctxPath == null) return; String nPath=("".equals(ctxPath)) ? "/" : ctxPath; mod_jk.println(); mod_jk.println(indent + "JkMount " + nPath + " " + jkWorker ); if( "".equals(ctxPath) ) { mod_jk.println(indent + "JkMount " + nPath + "* " + jkWorker ); if ( context.getParent() instanceof Host ) { mod_jk.println(indent + "DocumentRoot \"" + getApacheDocBase(context) + "\""); } else { mod_jk.println(indent + "# To avoid Apache serving root welcome files from htdocs, update DocumentRoot"); mod_jk.println(indent + "# to point to: \"" + getApacheDocBase(context) + "\""); } } else { mod_jk.println(indent + "JkMount " + nPath + "/* " + jkWorker ); } } private void generateNameVirtualHost( PrintWriter mod_jk, String ip ) { if( !NamedVirtualHosts.containsKey(ip) ) { mod_jk.println("NameVirtualHost " + ip + ""); NamedVirtualHosts.put(ip,ip); } } // -------------------- Apache serves static mode -------------------- // This is not going to work for all apps. We fall back to stupid mode. protected void generateContextMappings(Context context, PrintWriter mod_jk ) { String ctxPath = context.getPath(); Host vhost = getHost(context); if( noRoot && "".equals(ctxPath) ) { log("Ignoring root context in non-forward-all mode "); return; } mod_jk.println(); mod_jk.println(indent + "#################### " + ((vhost!=null ) ? vhost.getName() + ":" : "" ) + (("".equals(ctxPath)) ? "/" : ctxPath ) + " ####################" ); mod_jk.println(); // Dynamic /servet pages go to Tomcat generateStaticMappings( context, mod_jk ); // InvokerInterceptor - it doesn't have a container, // but it's implemented using a special module. // XXX we need to better collect all mappings if(context.getLoginConfig() != null) { String loginPage = context.getLoginConfig().getLoginPage(); if(loginPage != null) { int lpos = loginPage.lastIndexOf("/"); String jscurl = loginPage.substring(0,lpos+1) + "j_security_check"; addMapping( ctxPath, jscurl, mod_jk); } } String [] servletMaps = context.findServletMappings(); for(int ii=0; ii < servletMaps.length; ii++) { addMapping( ctxPath, servletMaps[ii] , mod_jk ); } } /** Add an Apache extension mapping. */ protected boolean addExtensionMapping( String ctxPath, String ext, PrintWriter mod_jk ) { if( debug > 0 ) log( "Adding extension map for " + ctxPath + "/*." + ext ); mod_jk.println(indent + "JkMount " + ctxPath + "/*." + ext + " " + jkWorker); return true; } /** Add a fulling specified Appache mapping. */ protected boolean addMapping( String fullPath, PrintWriter mod_jk ) { if( debug > 0 ) log( "Adding map for " + fullPath ); mod_jk.println(indent + "JkMount " + fullPath + " " + jkWorker ); return true; } /** Add a partially specified Appache mapping. */ protected boolean addMapping( String ctxP, String ext, PrintWriter mod_jk ) { if( debug > 0 ) log( "Adding map for " + ext ); if(! ext.startsWith("/") ) ext = "/" + ext; if(ext.length() > 1) mod_jk.println(indent + "JkMount " + ctxP + ext+ " " + jkWorker ); return true; } private void generateWelcomeFiles(Context context, PrintWriter mod_jk ) { String wf[]=context.findWelcomeFiles(); if( wf==null || wf.length == 0 ) return; mod_jk.print(indent + " DirectoryIndex "); for( int i=0; i<wf.length ; i++ ) { mod_jk.print( wf[i] + " " ); } mod_jk.println(); } /** Mappings for static content. XXX need to add welcome files, * mime mappings ( all will be handled by Mime and Static modules of * apache ). */ private void generateStaticMappings(Context context, PrintWriter mod_jk ) { String ctxPath = context.getPath(); // Calculate the absolute path of the document base String docBase = getApacheDocBase(context); if( !"".equals(ctxPath) ) { // Static files will be served by Apache mod_jk.println(indent + "# Static files "); mod_jk.println(indent + "Alias " + ctxPath + " \"" + docBase + "\""); mod_jk.println(); } else { if ( getHost(context) != null ) { mod_jk.println(indent + "DocumentRoot \"" + getApacheDocBase(context) + "\""); } else { // For root context, ask user to update DocumentRoot setting. // Using "Alias / " interferes with the Alias for other contexts. mod_jk.println(indent + "# Be sure to update DocumentRoot"); mod_jk.println(indent + "# to point to: \"" + docBase + "\""); } } mod_jk.println(indent + "<Directory \"" + docBase + "\">"); mod_jk.println(indent + " Options Indexes FollowSymLinks"); generateWelcomeFiles(context, mod_jk); // XXX XXX Here goes the Mime types and welcome files !!!!!!!! mod_jk.println(indent + "</Directory>"); mod_jk.println(); // Deny serving any files from WEB-INF mod_jk.println(); mod_jk.println(indent + "# Deny direct access to WEB-INF and META-INF"); mod_jk.println(indent + "#"); mod_jk.println(indent + "<Location \"" + ctxPath + "/WEB-INF/*\">"); mod_jk.println(indent + " AllowOverride None"); mod_jk.println(indent + " deny from all"); mod_jk.println(indent + "</Location>"); // Deny serving any files from META-INF mod_jk.println(); mod_jk.println(indent + "<Location \"" + ctxPath + "/META-INF/*\">"); mod_jk.println(indent + " AllowOverride None"); mod_jk.println(indent + " deny from all"); mod_jk.println(indent + "</Location>"); if (File.separatorChar == '\\') { mod_jk.println(indent + "#"); mod_jk.println(indent + "# Use Directory too. On Windows, Location doesn't" + " work unless case matches"); mod_jk.println(indent + "#"); mod_jk.println(indent + "<Directory \"" + docBase + "/WEB-INF/\">"); mod_jk.println(indent + " AllowOverride None"); mod_jk.println(indent + " deny from all"); mod_jk.println(indent + "</Directory>"); mod_jk.println(); mod_jk.println(indent + "<Directory \"" + docBase + "/META-INF/\">"); mod_jk.println(indent + " AllowOverride None"); mod_jk.println(indent + " deny from all"); mod_jk.println(indent + "</Directory>"); } mod_jk.println(); } // -------------------- Utils -------------------- private String getApacheDocBase(Context context) { // Calculate the absolute path of the document base String docBase = getAbsoluteDocBase(context); if (File.separatorChar == '\\') { // use separator preferred by Apache docBase = docBase.replace('\\','/'); } return docBase; } private String getVirtualHostAddress(String vhost, String vhostip) { if( vhostip == null ) { if ( vhost != null && vhost.length() > 0 && Character.isDigit(vhost.charAt(0)) ) vhostip=vhost; else vhostip="*"; } return vhostip; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -