Tomcat deployment project Virtual host virtual path configuration

Source: Internet
Author: User
Tags web services tomcat server
MyEclipse + TOMCAT deployment Java EE project:

Friends who learn Java EE development may have used MyEclipse + tomcat to develop and deploy their own web projects, and the following path is usually required to access the project in the browser after successful deployment:

Probably a lot of people know, in fact that behind the index.jsp is not input, because if the index.jsp is the default access page, the server automatically for us to return the page. The configuration of the default access page is set in Web-inf/web.xml:

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

This is usually generated automatically when a new project is created, and we can modify it to the home page that we want to set up.

In fact, in addition to this index.jsp can not write, the front of a series of addresses we can also be modified, such as we can implement input:

Http://www.myweb.com

came up to the same access effect. The following are detailed steps for setting:

1. Configure virtual path:

1.1 First right-click the--> Property (properties) on your own item in MyEclipse the following dialog box pops up:

Click on the left side of the MyEclipse, and then tap the Web, as shown in the image above.

Where Web-root folder: is the root directory of your Web services, for the web needs of the file resources are in this directory, generally default to Webroot, we do not need to modify.

The Web Context-root is the root of the project deployment, and the process of deploying the project is actually to copy the Webroot folder under our project to the WebApps folder under the Tomcat installation directory and rename the Web context-root name that we set , which is the name of the project we want to enter in the browser.

Therefore, if we do not want to enter the project name, then set it to none, that is, only keep/. Click "OK"!

1.2 Then to deploy our project:

At this point you will find that the previously deployed items are missing, it's okay, we re add:

When you choose Tomcat, you'll notice the following pop-up prompts:

It means your project will be deployed with Tomcat's default project because you don't have the project name set, and Tomcat's default project path is the root directory under WebApps, and if you deploy with the default project, the original root directory will be replaced. So let you choose how to handle the original root directory, for future recovery needs, we should choose the first method: that is, before the deployment of the original file backup, when your deployment is canceled and then restore the original file. Then click Finish, click OK, start Tomcat server, enter in browser

http://localhost:8080 carriage return is not to see Tom Cat.

2. Modify the default port

The first two questions are described:

Why do you want to enter 8080? Because 8080 is the default port for Tomcat, access Tomcat must be entered.

Why do not use the input port when accessing the Web page normally. Because the other server defaults to port 80, and port 80 is the default port for browsing Web services, you can not lose.

So we can also change the default port of Tomcat to 80, the answer is YES!

Modification method: In the Tomcat installation directory, find the Conf folder, in the Conf folder has a Server.xml file, this is the Tomcat server configuration file, many properties can be configured here.

Search for 8080 directly after opening the file, or browse to find the following sentence:

<connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/>

Quite simply, change the 8080 to 80 to save the file.

It is important to note that after the configuration file is modified, it is generally necessary to reboot the server before it takes effect.

OK, after restarting Tomcat, go to the browser to enter http://localhost to see what effect.

3, configure the virtual host

As the name suggests, localhost means the local host, which is the host of the server we are going to visit. It is also just a local host of the test ip:127.0.0.1 a surrogate.

Introduce this test IP:

We know that in IPv4, the IP address is divided into a, B, C three class and special address D and E according to the network number and host number. Between Class A and B have a 127.0.0.1 is a reserved address, it is called the local loopback address, the main role is two: first, test the network configuration of the machine, can ping pass 127.0.0.1 that the computer network card and IP protocol installation is not a problem; another effect is some server/ Client applications need to invoke resources on the server at run time, typically to specify the IP address of server, but when the program is running on the same machine without other servers, the server's resources can be installed on the computer. The IP address of the server is set to 127.0.0.1 and can also be run.

For most habits, localhost is essentially pointing to the local IP address of 127.0.0.1. There is a configuration file in the operating system (the path in WINDOWS is C:\WINDOWS\system32\drivers\etc\hosts) that binds localhost to 127.0.0.1.

Therefore, as long as the 127.0.0.1 is unchanged, localhost can be changed at will, but in order not to affect other projects continue to use localhost, I just add a binding 127.0.0.1www.myweb.cn to it. This is called a virtual host, We can add a lot of virtual hosts here.

# Copyright (c) 1993-2001 Microsoft Corp.

#

# This file has been automatically generated for use by Microsoft Internet

# Connection sharing. It contains the mappings of IP addresses to host names

# for the home network. Please don't make changes to the HOSTS. ICS file.

# Any changes could result in a loss of connectivity between machines on the

# Local network.

#

127.0.0.1 localhost

127.0.0.1 www.myweb.cn

There should be a space between the IP and the host name.

Ok. Save. Go to the browser to enter this web site, witness the Miracle Bar.

Also remind you not to set the name of the virtual host to the same name as your usual URL, such as: www.baidu.com, because this will cause your access request will not be sent to the Internet, but return to your host.

Of course, if you want to block out some websites, then set it here!!

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.