Windows installation and configuration Tomcat server tutorial -- remote access from external network

Reprinted from cpolar article: External network access to local Tomcat server [cpolar intranet penetration]

foreword

As a lightweight server, Tomcat not only has an interesting name (reminiscent of childhood), but also has powerful functions. Because it can load JavaWeb programs, it has become a necessary environment software for configuring JSP and Java systems, and is also a tool for development and debugging. The first choice for JSP programs. Tomcat runs stably and is open source and free. With the blessing of apache and Sun, it is free and open source, making it widely used in small and medium-sized systems and scenarios with fewer concurrent access users. However, if you want to make Tomcat web pages accessible in the public Internet environment, you need the assistance of cpolar intranet penetration. Now. The author will introduce to you how to use cpolar intranet penetration to publish Tomcat web pages to the public Internet.

1. Local Tomcat web page construction

Tomcat has many advantages. In order to save everyone's time, the author will not go into details here, and directly enter the installation settings of Tomcat. As an open source free software, Tomcat can be found and downloaded on its official website ( https://tomcat.apache.org ). The operating system used by the author is Windows, and the JDK version is 17.

On the Tomcat official website, we find the download page of the latest version, click the corresponding operating system version to download.

20230323091801

1.1 Tomcat installation

After the download of the required version of the Tomcat program file is completed, it can be installed. First, decompress the downloaded compressed file. But leave it alone for now.

20230323091802

1.2 Configure environment variables

After the download is complete, don’t worry about operating Tomcat, but configure the environment variables. Specifically, right-click, 我的电脑select 属性on the opened 系统page 高级系统设置, and click 环境变量the button to enter the environment variable settings.

20230323091803

20230323091804

20230323091805

2023032309180601

On 环境变量the page, create a new CATALINA_HOME system variable and make the following settings:

  • Variable name: CATALINA_HOME
  • Variable value: E:\test software\apache-tomcat-10.1.7 [The variable value is the decompression location of tomcat, you can click the "Browse Directory" button under the "Variable Value" column to select the path.

After the variable name and variable value are set, click 确认Save.

2023032309180701

Next, select an existing Pathentry, click the button, click on the right side of the 编辑pop-up page , add the following command to the command list, and click the button to save the changes. The added variable values ​​are:编辑环境变量新建确认

  • %CATALINA_HOME%\lib
  • %CATALINA_HOME%\lib\servlet-api.jar
  • %CATALINA_HOME%\lib\jsp-api.jar

2023032309180801

20230323091809

At this point, the setting of environment variables is complete. The next step is to set up tomcat

1.3 Environment Configuration

conf文件夹After setting the environment variables, we need to modify the files under tomcat user.xmland add a user that can run.

confAccording to the decompression location of tomcat, find the folder in it , open the folder, and find tomcat-user.xmlthe file.

20230323091810

20230323091811

After finding this file, double-click to open it, and add the following code to the last line of the file:

<role rolename="manager-gui"/> 
<role rolename="admin-gui"/>  
<user username="admin" password="admin" roles="admin-gui"/>
<user username="tomcat" password="admin" roles="manager-gui"/>

20230323091812

After the code is added, save and exit.

1.4 Tomcat running test

After completing the environment variable setting and adding the tomcat user, you can open the tomcat directory bin文件夹and double-click startupto start tomcat.

20230323091813

After starting tomcat, we can see that tomcat outputs through port 8080, so just enter in the address bar of the local computer browser localhost:8080to open the home page of tomcat.

20230323091814

At this time, tomcat is still in its original state. As for how to make a web page that looks good, it is not the main purpose of this article. Next, we have to find a way to create a data tunnel that can penetrate the intranet for the tomcat web page, so that it can be accessed by users of the public Internet.

1.5 Cpolar installation and registration

Compared with the complex settings of tomcat, the installation and use of cpolar intranet penetration is obviously much simpler. Just log in to the official website of cpolar ([ https://www.cpolar.com/ ]), find 下载the button on the top of the homepage, and Find the corresponding version of the software download on the download page of cpolar (the author uses the Windows operating system, so choose the Windows version to download).

20230323091815

20230323091816

After the Cpolar installer is downloaded, unzip it to the local computer, double-click the unzipped .msifile, and follow the next step to complete the installation. Of course, you can also choose the cpolar installation folder during installation, which is also a routine operation.

20230323091817

20230323091818

Since cpolar will create an independent data tunnel for each user, supplemented by user passwords and token codes to ensure data security, we need to register users before using cpolar. The registration process is also very simple. Just click on the upper right corner of the cpolar homepage 用户注册and fill in the necessary information on the registration page to complete the registration.

20230323091819

20230323091820

2. Local web publishing

So far, we have created a webpage with tomcat and can access it on the local address. The cpolar that provides intranet penetration data tunnel has also been installed and registered. Next, we can use cpolar to create a data tunnel and publish the local tomcat to the public Internet.

Since the data tunnel of cpolar free version is reset every 24 hours. The author does not want to reconnect tomcat webpage settings every day, so I upgraded cpolar to the vip version in order to obtain a long-term stable intranet penetration data tunnel.

2.1. Cpolar cloud settings

To achieve the purpose of intranet penetration, you need to log in to cpolar's official website first, find the 预留button on the left side of the user's main page, and click to enter the reserved page of cpolar's data tunnel. A public Internet address is generated here (it can also be regarded as the entrance of the data tunnel). At this time, the public Internet address is not connected to the output port of the local webpage, so it can also be regarded as a blank data tunnel.

20230323091821

On the reservation page, you can see many kinds of data tunnels that can be reserved. Here we select 保留二级子域名the field. Of course, if you have your own domain name, you can also choose 保留自定义域名the column, but you need to analyze your own domain name at the domain name provider before you can use it with cpolar.

20230323091822

In 保留二级子域名the field, you need to make simple settings for several items of information:

  • 地区: The area where the server is located, just select the nearest one
  • 二级域名: Will eventually appear in the generated public Internet address as one of the identifiers of the network address
  • 描述: It can be regarded as the description of this data tunnel, which can be distinguished from other tunnels

After completing these settings, you can click 保留the button on the right to keep this data tunnel.

20230323091823

20230323091824

Of course, if this data tunnel is no longer intended to be used, you can also click on the right xto delete it easily, saving valuable tunnel quota.

2.2 Cpolar local settings

After completing the setting of cpolar cloud and keeping the blank data tunnel, you can return to the cpolar client of the local computer and connect the blank data tunnel generated by the cloud with the local Alipay test page, so that we can access tomcat on the public Internet web pages.

Open and log in to the cpolar client locally (you can enter localhost:9200 in the browser to access directly, or click the shortcut of the cpolar client in the start menu), click the button on the left side of the main interface of the client to enter the 隧道管理local 创建隧道tunnel Create a page (if you want to create a temporary data tunnel without a 24-hour reset address, you can directly set it here instead of setting a blank data tunnel on the cpolar official website).

On this page, several information settings also need to be made, including:

  1. 隧道名称– It can be regarded as the local tunnel information comment of cpolar, as long as it is convenient for us to distinguish;
  2. 协议– Tomcat outputs web pages, so choose the http protocol;
  3. 本地地址– The local address is the output port number of the local website, and the default output port of tomcat is 8080, so fill in 8080 here;
  4. 域名类型– In this example, we have reserved the data tunnel of the second-level subdomain name in the cpolar cloud, so check the "Second-level subdomain name" (if the reserved domain name is a custom domain name, check the custom domain name), and Fill in the reserved second-level subdomain name in the "Sub Domain" column on the next line, here we fill in "tomcattest" (if you just create a temporary data tunnel, check "random domain name" directly, and the network address will be generated by the cpolar client );
  5. 地区– Same as the cpolar cloud setting, we fill in according to the actual location;

20230323091825

After completing the data tunnel connection between the cpolar client and the cpolar cloud, the cpolar client will automatically jump to the page 隧道管理under 隧道列表the item, where we can see the status of the data tunnel (whether it is smooth), or control the opening and closing of the tunnel or delete. If you need to change the information of the tunnel, you can also use the "Edit" button here

20230323091826

And the public Internet address of this data tunnel can be seen on the 状态- 在线隧道列表page.

20230323091827

3. Public network access test

We paste the public Internet address generated by cpolar intranet penetration into the address bar of the browser of other computers, and we can see that the tomcat webpage on the local computer can be displayed. It means that we have successfully used cpolar intranet penetration to publish the local tomcat webpage to the public Internet.

20230323091828

4. Conclusion

Although it seems that this article is very long, in actual operation, it will delay for a while when setting environment variables in tomcat, and the data tunnel setting part of cpolar can be completed soon. In fact, not only tomcat, but other web servers, as long as you know the output port of the software (web page), you can use cpolar to create a data tunnel that penetrates the intranet and publish this software (web page) to the public Internet.

Guess you like

Origin blog.csdn.net/m0_65485317/article/details/130704557