Configure Apache + Tomcat to support multiple applications, that is, multiple secondary domain names

1. Environment

Apache2. 0.43. 0

Tomcat 4.1. thirteen

mod_ jk-2.0. forty-three

jdk 1.4

Windows 2003

Key file location:

Server. xml:$tomcat_ home/conf

Httpd. conf:$apache_ home/conf

Mod_ jk. conf:$tomcat_ home/jk/

2. Hypothetical background

Suppose the top-level domain name www.abc COM, to set up site1 abc. COM and site2 abc. com。 Two secondary site applications, site1 and site2, are on the same server, assuming the external IP: 100.100 one hundred point one zero zero

3、 mod_ JK integrates Apache and Tomcat

This content has many introductions on the Internet, which is also very simple. I won't say it here.

4. Add Tomcat virtual host

Open Tomcat's server XML file, modify the default host segment, similar to the following:

<Host name="site1.abc.com" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true">
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="localhost_log." suffix=".txt"
        timestamp="true"/>
           <Context path="" docBase="d://workspace//site1//webapp//" debug="0"
                                                 reloadable="true" crossContext="true">    
           </Context>
      </Host>

And add site2 virtual host, similar to the following:

<Host name="site2.abc.com" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true">
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="localhost_log." suffix=".txt"
        timestamp="true"/>
           <Context path="" docBase="d://workspace//site2//webapp//" debug="0"
                                                 reloadable="true" crossContext="true">    
           </Context>
      </Host>

Notice the bold text in red and blue.

Site2 is actually copying site1 and modifying the blue part.

Of course, according to your specific situation, you can also add or modify other configurations.

5. Add Apache virtual host

Open Apache's httpd Conf file, add something similar to the following in the last virtualhost section:

<VirtualHost *:80>
ServerName site1.abc.com
DocumentRoot "d:/workspace/site1/webapp"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.abc.com
DocumentRoot "d:/workspace/site2/webapp"
</VirtualHost>

Here, the content of DocumentRoot is generally consistent with the docbase in the context of Tomcat.

Find #namevirtualhost *, which is commented out by default and modified as:

NameVirtualHost *:80

If you do not open this configuration, Apache will report an error "default virtualhost overlap on port 80, the first has precedence"

If ": 80" is not added, it can run, but Apache startup will report an error.

VirtualHost *:80--mixing * prot and non-* ports with a NameVirtualHost address is not supported,proceeding with undefined results

6. Hosts configuration

Because there is no DNS resolution on this machine, when testing, enter site1. 0 in the browser address bar abc. COM, can't find the server. In order to test, we need to add such a host so that Apache can find the host.

Text open the windows / system32 / Drivers / etc / hosts file and add two lines

127.0.0.1 site1.abc.com
127.0.0.1 site2.abc.com

Start Apache and Tomcat services and type site1. 0 in the address bar abc. COM and site2 abc. com。 It should be accessible.

7. Actual deployment

During actual deployment, of course, you do not need to modify the hosts file, because the hosts file is only valid for the machine. Usually, the ISP provider should have a system to define the secondary domain name forwarding, where the IP corresponding to the secondary domain name is defined.

site1.abc.com--->100.100.100.100
stei2.abc.com--->100.100.100.100

In this way, you can actually access two secondary domain names. However, after DNS is configured, it may not take effect immediately. It is said that it takes 2 ~ 24 hours to take effect.

8. Other

Although there is basically no problem after the above configuration, because each application uses different technologies, abnormal access may occur.

If struts framework is used, it is found that * If the do request does not respond, modify mod_ jk. Conf file, add

JkMount /*.do ajp13

If you want the default page to be login JSP instead of index JSP, modify httpd The directoryindex of conf will log in JSP to index JSP front

Of course, all the above are basic configurations, and there are many detailed configurations. In fact, I won't.

The above configuration is also made with the help of friends. Write it down. I hope it can help friends in need.

Please correct any mistakes.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>