Installation configuration for Apache-tomcat

Source: Internet
Author: User

You will now use some of Tomcat's experience and insights to write here, as a record and memo. If you have a friend to see, please do not hesitate to enlighten.

1. The first is Tomcat acquisition and installation.

Get the official website of Apache to download, open source is free, and bandwidth is enough. The download will be quick.

  

This is two different downloads, one is the normal installation version, the other is the decompression installation version. It's the same, but there are some interfaces in the normal installation that provide quick settings for Tomcat, and a normal installation will register Tomcat as a system service.

2. Tomcat's operating environment is built.

(decompression version) installation (is decompression) after the completion of the following:

  

Tomcat Startup is a bat file (under Windows), in the Bin directory. You can double-click.

If the startup is unsuccessful, the general situation is that the console comes out immediately and disappears, indicating that Tomcat did not find the Java Runtime environment.

The simple understanding is that Tomcat cannot find the JDK and is not able to run.

We "tell" the installation path of its JDK. Create a new java_home (case insensitive) in the environment variable, pointing to the JDK installation directory. As follows:

  

In this way, Tomcat is configured, and the boot is OK.

Launch Tomcat, enter http://localhost:8080/in the browser address bar if you see a messy introduction to Tomcat about the god horse, the configuration is successful.

3. The directory structure of Tomcat is introduced.

The bin directory holds some executable programs and related content that start running Tomcat.

Conf stores the global configuration about the Tomcat server.

The Lib directory holds the jar packages required for Tomcat to run or the site to run, and all the sites on this Tomcat share these jar packages.

The Wabapps directory is the default site root directory and can be changed.

The work directory is used for excessive resources when the server is running, simply to store the JSP, servlet translation, and compiled results.

Other directories and files are not introduced for the time being.

4. Tomcat's default behavior.

When our browser request arrives at Tomcat and the request is correct, Tomcat typically responds 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, www.baidu.com)

      Port number (the HTTP protocol defaults to 80, so we generally make a request to a website without input)

      Site

      Resource Location

such as http://localhost:8080/ROOT/index.jsp

So in the second step we only entered the domain name (or host name) on the access to a specific page, what is the matter?

First, the request reaches the requested host address in some way and is obtained by the HTTP server program on the server (the hardware, such as our native computer). This step is more difficult to explain, we do not repeat, I will be in other space to introduce.

For example, we enter http://localhost:8080 into the browser. was found by Tomcat.

Now it gets the request to analyze what resources we are asking for. Because we do not specify, it will go to the default site to get the default page to us.

Now let's go through the process:

        Server-side: Tomcat listens on port 8080 and is always aware of requests coming in.

The client browser makes the request and arrives at the server side, and because of the port allocation, the request is eventually made available to Tomcat.

Tomcat parses the requested resource and discovers that it does not specify which resource under which site is required.

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

  

5. Change the tomcat default configuration.

①, modify the Tomcat listening port.

We've all had experience visiting the site. We generally only enter the domain name, then suppose we now as a network service provider, will publish the site, how can we let users only enter our domain name to see the page we prepared for him/her?

First we need to set the listening port to 80, it is very simple, the user does not enter in the browser: 8080来 access to the site, the browser will not automatically send the request to the server's 8080 port.

modified in the Server.xml file under the Conf directory under%tomcat_home% (the installation path of the following refers to TOMCAT).

  

There are a lot of things in this file, but you don't have to care. Why is it? You delete the comments and then treat the whole XML as an object, right, each node is a property, and this property can be an object, it has properties ... It is also true to understand this, or to think directly of Tomcat's configuration information.

In this way, you do not have to enter: 8080.

②, modify the default site.

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

Site, the server must be stored and managed with a folder (that is, the directory structure). However, it is different from the normal folder, in Tomcat, the folder that can be used as a site must have the following characteristics: A subfolder named Web-inf, which must have a file named Web. XML, must be constrained with a specific DTD.

      

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

Configure the site: Create a folder, create a Web-inf subfolder, create the Web. XML, complete. The Web. Xml content can refer to Webapps/root/web-inf/web.xml.

Set as Default site:

This needs to be done in two steps.

Tell Tomcat that you came to me when you requested the site (or what name was behind the domain name).

Tell Tomcat where I am.

  

            Two steps have been configured (in fact Tomcat adds the code that points to the empty site to root), our D:/myweb:

If your site is stored in the WebApps directory, you can use a relative path, for example, we will d:/myweb the entire copy to%tomcat_home%/webapps under, the docbase obviously does not need to add d:/.

  

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

  

③, modify the default page.

In the above, we are quite the norm, according to the common sense of the card, thanks to index.html. So what if it's not written? What will Tomcat do?

Please find Conf/web.xml. This file is a set of common properties for all sites. For example, people look at the end of the file:

  

This is called the Welcome page, and when no resource address is entered, it is searched from top to bottom to get the page and respond.

Very clear, change it can be, but not recommended to change here, will be all site settings changes, you should copy it to the site you need to change the Web. XML, to set.

6, the configuration of the virtual host.

The so-called virtual host is to bind one or more host names (domain names) to the server where Tomcat resides. Because an IP can and multiple domain names to help, we can point to different domain names on the server (refers to the hardware) on the different folders, resulting in a server (or an IP) multiple hosts "virtual host" effect.

This is quite simple to implement. You only need to create a new host node in the Server.xml file and set its properties differently.

1#你的主机名 (domain name) 12<HostName= "localhost"AppBase= "WebApps"3Unpackwars= "true"Autodeploy= "true"4Xmlvalidation= "false"Xmlnamespaceaware= "false">5</Host>6#你的域名27<HostName= "Www.coderecord.org"AppBase= "Host Space Address"8Unpackwars= "true"Autodeploy= "true"9Xmlvalidation= "false"Xmlnamespaceaware= "false">10#域名3可以和域名2共用一个主机空间11<alias>coderecord.org </alias>12 <context path< Span style= "color: #0000ff;" >= ""  Docbase= "Site Address"  Debug= "1"  Reloadable= "True"  Allowlinking=" true " />13 </host>           

Installation configuration for Apache-tomcat

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.