Tomcat installation configuration)

Source: Internet
Author: User
1. First, get and install Tomcat.

Download from Apache's official website. It is open-source and free, and the bandwidth is sufficient. The download will be fast.

  

There are two different download Methods: A common installation version and a decompressed installation version. The usage is the same, but there are some interfaces in the general installation version that can provide quick settings for Tomcat, and the general installation will register Tomcat as a system service.

2. Set up the Tomcat runtime environment.

(Decompress version) after installation (that is, decompress) is completed as follows:

  

Tomcat is started as a bat file (in Windows) under the bin directory. Double-click.

If it fails to be started, the console disappears immediately after it comes out, indicating that Tomcat does not find the Java Runtime Environment.

Simply put, it means that Tomcat cannot find JDK and cannot run.

Let's "tell" the JDK installation path. Create java_home (case-insensitive) in the environment variable and point to the JDK installation directory. As follows:

  

In this way, Tomcat is configured and started.

Start Tomcat and enter http: // localhost: 8080/in the address bar of the browser. If you see a messy introduction to Tomcat, the configuration is successful.

3. Tomcat directory structure introduction.

The bin directory stores executable programs and related content for starting and running tomcat.

Conf stores the global configuration of the Tomcat server.

The lib directory stores the jar packages required for Tomcat running or site running. All the sites on Tomcat share these jar packages.

The wabapps directory is the default site root directory, which can be changed.

The work directory is used to store excessive resources during server running. In short, it is to store JSP, Servlet translation, and compiled results.

Other directories and files are not described at the moment.

4. Default Tomcat behavior.

If a browser request arrives at Tomcat and the request is correct, Tomcat usually responds to the request in the form of a static page (that is, an HTML file), which is the default behavior of the HTTP server.

A complete resource request includes:

Protocol (such as HTTP)

Host Name (domain name, such as localhost and www.baidu.com)

Port Number (the default HTTP protocol is 80, so we generally do not enter a request to a website)

Site

Resource location

For example, http: // localhost: 8080/root/index. jsp

In the second step, we only enter the domain name (or host name) to access a specific page. What is the problem ?.

First, the request will arrive at the requested host address in some ways and be obtained by the HTTP server program on the server (hardware, such as our local computer. This step is difficult to explain. We will not repeat it here. I will introduce it in other sections.

For example, enter http: // localhost: 8080 in the browser. Tomcat found.

Now it gets the request and analyzes the requested resources. Because we didn't specify it, it will go to the default site to get the default page for us.

Now let's go through the process again:

Server: Tomcat listens to port 8080. always pay attention to the request.

The client browser sends a request to the server. Due to port allocation, the request is finally obtained by Tomcat.

Tomcat parses the requested resource and finds that no resource is specified for the site.

Tomcat returns the default page to the client browser as a response under the default site.

  

5. Change the default tomcat configuration.

① Modify the Tomcat listening port.

We have all experienced Website access. We generally only enter the domain name, right? Suppose we are now a network service provider and will release the website to the outside world, how can we let the user enter our domain name only to see the webpage we have prepared for him/her?

First, we need to set the listening port to 80. The principle is very simple. The user will not enter 8080 in the browser to access the website, and the browser will not automatically send the request to port 8080 on the server.

Modify it in the server. xml file in the conf directory of % atat_home % (which is the installation path of Tomcat.

  

There are a lot of things in this file, so you don't have to worry about it. Why? After you delete the comment, you can regard the entire XML as an object. Right? each node is an attribute, and this attribute may be an object. It contains attributes ...... To understand this, or directly think That tomcat configuration information is correct.

In this way, you do not need to enter 8080.

② Modify the default site.

First, the site is a folder with a specific structure. This is extremely clear in Tomcat.

Websites must be stored and managed using folders (directory structure) on the server. But it is different from the common folder, in Tomcat, can be used as a site folder must have the following features: Have a sub folder named WEB-INF, the sub-folder must have a name named Web. XML file, and the XML file must be bound with a specific DTD.

      

We first configure or create a site, and then set it as the default site.

Configure site: Create folder, create WEB-INF subfolders, create web. XML, complete. For Web. XML content, see webapps/root/WEB-INF/Web. xml.

Set as default site:

You can perform this operation in two steps.

Tell Tomcat which site to request (or what name is followed by the domain name) and you will come to me.

Tell Tomcat where I am.

  

We have configured the two steps (in fact, Tomcat adds the code to point the empty site to the root by default), and our D:/myweb:

If your website is stored in the webapps directory, you can use the relative path. For example, we copied D:/myweb to % atat_home %/webapps, obviously, you do not need to add D.

  

I wrote a few words in index.html and the result came out:

  

③ Modify the default page.

In fact, we are still in a regular fashion. As usual, we thanked index.html. So what if it is not written? What Will Tomcat do?

Find CONF/Web. xml. This file sets the common attributes of all sites. For example, you can see at the end of the file:

  

This is called the welcome page. When the resource address is not entered, it will be searched from top to bottom, get the page, and respond.

You can change it clearly, but it is not recommended to change it here. It will be a change in the settings of all sites. You should copy it to the web under the site you want to change. XML.

6. Configure the VM.

The so-called virtual host is to bind one or more host names (Domain Names) to the server where Tomcat is located. Since one IP address can be customized with multiple domain names, we can direct different domain names to different folders on the server (hardware) to create a server (or an IP address) the "virtual host" effect of multiple hosts.

This implementation is quite simple. You only need to create a host node in the server. xml file and set its attributes differently.

1 # Your host name (Domain Name) 1
2
5
6 # your domain name 2
7
10 # Domain Name 3 can share a host space with domain name 2
11 coderecord.org
12
13

The above configuration information varies depending on the tomcat version.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.