Article directory
- foreword
- 1. Local Tomcat web page construction
-
- 1.1 Tomcat installation
- 1.2 Configure environment variables
- 1.3 Environment configuration
- 1.4 Tomcat running test
- 1.5 Cpolar installation and registration
- 2. Local web publishing
-
- 2.1. Cpolar cloud settings
- 2.2 Cpolar local settings
- 3. Public network access test
- 4. Conclusion
Reproduced from the article of cpolar intranet penetration: 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 webpage 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.
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.
1.2 Configure environment variables
After the download is complete, do not worry about operating Tomcat, but configure the environment variables, specifically, right-click My Computer
and click Properties
, in the opened On the System
page, select Advanced System Settings
, and click the Environment Variables
button to enter the environment variable settings.
On the Environment Variables
page, create a new CATALINA_HOME system variable and set the following:
- 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 OK
to save.
Next, select the existing Path
entry, click the Edit
button, and click New< on the right side of the pop-up
Edit Environment Variables
page /code>, add the following commands to the command list, and click the OK
button to save the changes.
The added variable values are:
- ?TALINA_HOME%\lib
- ?TALINA_HOME%\lib\servlet-api.jar
- ?TALINA_HOME%\lib\jsp-api.jar
At this point, the setting of environment variables is complete. The next step is to set up tomcat
1.3 Environment Configuration
After completing the environment variable setting, we need to modify the user.xml
file under the conf folder
of tomcat to add an executable user.
According to the decompression location of tomcat, find the conf
folder in it, open the folder, and find the tomcat-user.xml
file.
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"/>
After the code is added, save and exit.
1.4 Tomcat running test
After setting the environment variable and adding the tomcat user, you can open the bin folder
under the tomcat directory, and double-click startup
to start tomcat.
After starting tomcat, we can see that tomcat outputs through port 8080, so as long as you enter localhost:8080
in the address bar of the local computer browser, you can open the homepage of tomcat.
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/]) and find at the top of the homepage Click the Download
button, 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).
After the Cpolar installation program is downloaded, unzip it to the local computer, double-click the unzipped .msi
file, and follow the steps to complete the installation. Of course, you can also choose the cpolar installation folder during installation, which is also a routine operation.
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 User Registration
in the upper right corner of the cpolar homepage, fill in the necessary information on the registration page, and the registration will be completed.
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, and find the Reserved
button on the left side of the user’s main page, and click to enter the cpolar data tunnel reserved page. 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.
On the reservation page, you can see a variety of data tunnels that can be reserved. Here we choose the reserve second-level subdomain name
field. Of course, if you have your own domain name, you can also choose to keep the custom domain name
field, but you need to analyze your own domain name at the domain name provider before it can be used with cpolar.
In the field Reserve the second-level subdomain name
, you need to set several simple information:
Region
: the region where the server is located, just select the nearest oneSecond-level domain name
: will eventually appear in the generated public Internet address as one of the identifiers of the network addressDescription
: 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 Reserve
button on the right to preserve this data tunnel.
Of course, if this data tunnel is no longer intended to be used, you can also click the x
on the right to 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, we 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), and click Tunnel Management
Click the Create Tunnel
button under the item to enter the local tunnel creation 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:
Tunnel name
– it can be regarded as cpolar’s local tunnel information comment, as long as it is convenient for us to distinguish;protocol
– tomcat outputs web pages, so choose http protocol;local address
– 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;Domain name type
– 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 reservation is a custom domain name, Then 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, directly check “random domain name” , the network address is generated by the cpolar client by itself);Region
– the same as the cpolar cloud setting, we fill in the nearest location according to the actual location;
After completing the data tunnel connection between the cpolar client and the cpolar cloud, the cpolar client will automatically jump to the Tunnel List
page under Tunnel Management
, where we can see To the state of the data tunnel (whether it is unblocked), or to control the opening, closing or deleting of the tunnel. If you need to change the information of the tunnel, you can also use the “Edit” button here
The public Internet address of this data tunnel can be seen on the Status
—Online Tunnel List
page.
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.
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.