Target and environment three-based virtual host configuration. Software download car
http://java.sun.com/j2se
http://www.apache.org/dist
Suppose all download files are all placed under / TMP Software Environment · Redhat Linux 9.0 · Jakarta-Tomcat-5.0.19.tar.gz · Jakarta-Tomcat-Connnectors-JK2-src-Current.tar.gz · HTTPD-2.0. 19 · J2SDK-1_4_2_04-Linux-i586-rpm.bin or · Redhat Linux 9.0 · Jakarta-Tomcat-4.1.30. TAR.GZ · JAKARTA-TOMCAT-Connnectors-4.1.30-src.tar.gz · httpd-2.0.19 · J2SDK-1_4_2_04-Linux-i586-rpm.bin is tested in the above two environments
The three virtual hosts respectively correspond to three different services, each virtual host can make a correct response to the request. This example, my IP address is 10.0.0.10, the corresponding three virtual hosts and the pair of directories are as follows
Www.home.net
/ VAR / WWW / HOMENET (default host)
www.customer1.it
/ var / www / custom0001it
www.customer2net
/ VAR / WWW / CUSTOMER2NET
Install JDK Note: Download JDK, not JRE!
Code: [User @ host TMP] #CHMOD 755 J2SDK-1_4_2_04-Linux-i586-rpm.bin [user @ host tmp] #. / J2sdk-1_4_2_04-linux-i586-rpm.bin [user @ host tmp] # rpm -IVH J2SDK-1_4_2_04-FCS-Linux-I586.rpm J2SDK is automatically installed in / usr / java directory
Code: [User @ host tmp] #cp -r /usr/java/j2sdk1.4.2_04 / usr / local / sdk can also be established to connect to /usr/java/j2sdk1.4.2_04/ here for convenience, I will Copy to / usr / local / SDK .. (or [user @ host tmp] #ln -s /usr/java/j2sdk1.4.2_04 / usr / local / sdk) Java environment now tells your Bash Shell where to find Java: Create a file called java.sh in the /etc/profile.d directory, the content is as follows: Code:
Code: [User @ host] ~ $ vi /etc/profile.d/java.sh # set java environment export java_home = / usr / local / sdk export path = $ path: $ java_home / bin export classpath = $ java_home / lib Save and change file permissions: Determine Java.sh can be read and write any user:
Code: [User @ host] ~ #Chmod 755 /etc/profile.d/java.sh [user @ host] ~ $ Which Java / USR / local / SDK / BIN / JAVA Used
Code: Which Java can get Java installation path. If you have installed Java, you can ignore this step. Install Apache to download the latest Apache version, install and compile:
Code: [User @ host] #tar zxvf httpd-2.0.49.tar.gz [user @ host] #CD httpd-2.0.49 [user @ host] #. / Configure --prefix = / usr / local / apache2 / / Specify Apache Installation Directory --Nable-Modules = SO // Load Apache in Dynamic Mode [User @ host] #make [user @ host] #make install Don't forget - Nenable-Module = SO, because loading apache -tomcat Connector When you use the following command: [User @ host] ~ # / usr / local / apache2 / bin / apachectl start Opens the browser View whether the Apache service is started normally.
Code: http: // localhost can generally see the version number, Apache defaults to install Tomcat using the 80-port installation Tomcat, and install it.
Code: [User @ Host TMP] ~ $ TAR ZXVF JAKARTA-TOMCAT-5.0.19.TAR.GZ [User @ Host TMP] ~ $ CP JAKARTA-TOMCAT-5.0.19-SRC / USR / local / Tomcat launch Tomcat:
Code: [User @ Host TMP] ~ $ /usr/local/tomcat/bin/startup.sh Using the bin / startup.sh and shutdown.sh and shutdown.sh in the Tomcat directory to start and stop Tomcat. In the browser with http: / / localhost: 8080 View Tomcat is started normally. If you can't start, check / usr / local / tomcat / conf / catalina.out log file until you can start. ######### The following is I am tested Problem encountered in the process ############### If you can't start, it may be that user permissions are not enough to increase user or change permission.
Code: GroupAdd Tomcat Useradd -g Tomcat -c "Tomcat User" -d / usr / local / tomcat tomcat passwd Tomcat chown -r Tomcat: Tomcat / usr / local / tomcat chmod a x / usr / local / tomcat configuration Tomcat listening AJP13 requesting from Apache is an example of a Server.xml configuration file. Note that the location of the directory and log file is any. You can change the location of the primary and log files based on your needs. // The following is a server.xml file that configures the virtual host (here I use 5.0.19 server.xml file, 4.1.30 is also roughly the same
Code: vi /usr/local/tomcat/conf/server.xml
Code: <-! Define a non-SSL Coyote HTTP / 1.1 Connector on port 8080 ->
Code: ########## Defining the virtual host, change Host Name for your host name ## ##### ######### Change AppBase for your host's path #############
Code:
Code:
Code:
Code:
Code: /usr/local/tomcat/conf/jk2.properties and add the following: vi /usr/local/tomcat/conf/jk2.properties # list of needed handlers. Handler.list = ChannelSocket, Request # Override The Default Port For the channel = 8009 If you start normal, you can go to the next step. Configuring how to configure the Apache virtual host APAHCE Virtual host to configure how to configure the apache howto document http://httpd.apache.org/docs-2.0/vhosts/ Configure the Apache to Talk to Tomcat or connector download and your Apache version of the JK2 file to / TMP directory. If you can't find the corresponding JK2 version, you can ask or download the source file through the Tomcat-User mailing list and download the source file. (How to do this here is here) code: [User @ host tmp] # tar zxvf jakarta-tomcat-connectors-jk2-src-current.tar.gz [user @ host tmp] # CD JAKARTA-TOMCAT-Connectors -jk2.0.4-src [user @ host TMP] # cp -r jakarta-tomcat-connectors-jk2-2.0.4-src / usr / local / jk2 [user @ host TMP] #CD / USR / local / jk2 / JK / Native2 [User @ host tmp ]/ buildconf.sh [user @ host tmp] ./ Configure --with-apxs2 = / usr / local / apache2 / bin / apxs // Apache2 Using apxs2 --with-Tomcat = / usr / local / tomcat [user @ host] make [user @ host] cd / usr / local / jk2 / jk / build / jk2 / apache2 // can see mod_jk2.so [user @ host] cp mod_jk2.so / USR / local / apache2 /modules/mod_jk2.so creates a file called Workers2.Properties in the / usr / local / apache2 / conf directory, and edits this file, the content is as follows:
Code: # Only At Beginnin. In Production UNComment It Out [Logger.Apache2] level = debug [shm] file = / usr / local / apache / logs / shm.file size = 1048576 # Example Socket Channel, Override port and host. [channel.socket: localhost: 8009] Port = 8009 Host = 127.0.0.1 # define the worker [AJP13: localhost: 8009] channel: localhost: 8009 # URI mapping [URI: 127.0.0.1 / *. jsp ] worker = ajp13: localhost: 8009 [URI: 10.0.0.10 / *. jsp] worker = ajp13: localhost: 8009 [URI: www.home.net / *. jsp] worker = ajp13: localhost: 8009 [URI: WWW .customer1.it / *. jsp] worker = ajp13: localhost: 8009 [URI: www.customer2.net / *. jsp] worker = ajp13: localhost: 8009 Edit this file, change your IP address or domain name, And save. Edit http.conf and add the following line in Modules Section: LoadModule JK2_Module Modules / Mod_jk2.so saves http.conf to restart Apache. Now it will load the JK2 connector and read the configuration file from Workers2.properties. Check the log and confirm everything. Start Tomcat Test, and try to load an HTML page in your browser will return a page without a problem. Now try a JSP page, it shows you to wait for a while. If you return an error, you have to check if the path and the hostname are correct. (Carefully check the DNS configuration), Tomcat and Apache will read the host directory you set. Check the log file. All work is working properly. JK in httpd.conf In addition to the Workers2.Properties file name, you can JK indicates to join the httpd.conf file (just like you are using JK and WebApp mode). Edit the default host area in httpd.conf and add the following three lines before virtualhost>:
Code:
Code: LoadModule JK2_Module Modules / Mod_jk2.so ### Section 2: 'Main' Server Configuration ........................ #### ###### Change the default host name #####################
Code: servername www.home.com UsecanonicalName Off ################################################################################################################################################################################################################################################################################### ## Join the default first index.jsp ...............
Code: Directoryindex Index.html Index.jsp #
Code:
Code: NameVirtualHost 10.0.0.10