JAVAWEB project Tomcat and internal network penetration to achieve external network access, can connect mysql database

Every time I browse the Internet, I am very envious of others having their own website. Although they say that they can build javaweb, they have been running locally and have never run it on the Internet.

I have also learned about how to access this aspect of the Internet, but I have never said that it has been studied carefully, which has led to this matter until now. But today I made up my mind to make this matter clear. After referring to the teachings of the great gods on the Internet and my own understanding, I finally solved it today!

Next, start my recording:

 

1. Generate war package

First of all, you must have your own project, and then you need to understand the running path of tocamat, which is generally accessed through webapps in your own apache. Each time you run apache start.bat, it is equivalent to loading this folder in the browser interface. Project, so we need to find a way to put our own project under this directory. But you said that it is not advisable to directly copy and paste your javaweb project into this directory, so you cannot achieve the goal you want, you must have your own package here, so that it will be automatically parsed when apache runs About the packages under the webapps folder, so that you can achieve your desired goals. So what we need is to package the project first. Here I have idea to demonstrate how to package (idea step is more complicated, eclipse is relatively simple, right-click project export generates war package and then specify the location)

 

Project structure:

Note here that I take the lib directory marked by the line. The idea is two. I must specify the jar package to load, so the association must be built first. If the jar package to be loaded is not specified, even if it succeeds later, it cannot be connected. database. Therefore, we must pay attention, but I will not elaborate on how to specify the jar to be loaded. This is relatively simple.

 

Then to build the war package configuration this option is here:

Click the arrow pointed to by the arrow in the upper right corner of idea, and then find the Artifact column in the pop-up option box.

Then click the "+" in this box to find the third option under exploded

Then select the newly created war option, set the name and generation path of the war package in the pop-up place on the right, then run the project after apply and it will be generated at the specified location.

Regarding how to generate, I have also found related video screens on the Internet here, I believe it is easier to understand when combined: https://www.bilibili.com/video/av82894907

 

 

2. Prepare for intranet penetration

There are many tools for intranet penetration. I use "peanut shell" here, because the configuration is relatively simple and the trial version has free traffic experiments, which is easier to use.

After downloading and installing, it is registration and login. There is nothing to say about this.

 

Then it is to find the domain name. The website needs a domain name to log in, so you need to find your favorite domain name on the Internet. Of course this thing is suitable and inappropriate, but the price is different. I chose a free domain name, so the suffix is ​​more Long.

There are many online tutorials for finding free domain names. I will not elaborate here. I will put a link here and apply. https://www.zhihu.com/question/19835955

 

After you have a domain name, you need to link this domain name to your computer's intranet, so that when you open the tomcat service, you can access it through the domain name, so how to query your computer's IP address? Then enter ipconfig -all in the console to find it

 

Like here ipv4 is our ip value, remember to be useful when the time comes.

 

Then open our peanut shell software and establish the mapping relationship

Fill in the ip address you just wrote down in the following column, and then pay attention to the application type above to select HTTP, so that it can be accessed through the Internet.

 

 

3. Modify the apache configuration

The previous two are not completed, basically the same, next need to put the war package generated in the first step into the apache webapps directory on your computer

 

After finishing here, go back to the conf directory of the upper layer, find the server.xml file, we will modify it next

 

Find the host tag to modify the name inside, and also create a new Context tag to record your project name for pointing

 

Then run startup.bat in the bin directory and wait for the war package to load

tomcat running interface

 

After running, it will parse and unpack the war under webapps into a format that can be run on the server: generally such a folder will be generated

 

 (According to the principle, the Internet should be accessible through different directories, but I only display the contents under the ROOT folder, which is still a problem)

 

Now you are indeed able to access through your own domain name, but it is not your own project, it is the tomcat installation successful display interface, so here we need to replace the original ROOT folder in webapps, and change your file name to ROOT So that the server can read our own projects

 

At this point, all our steps have been completed, and we can now see our own projects through domain name access.

 

 

It was not so easy to set up the network this time, but I succeeded in the end. I still want to thank the network seniors who helped me!

 

Acknowledgement: https://blog.csdn.net/diyangxia/article/details/97272350

Guess you like

Origin www.cnblogs.com/himurayaiba/p/12728740.html