[Mobile website building] Android Termux+cpolar intranet penetration, build a website that can be accessed from the external network - no public network IP

overview

Termux is an Android terminal emulation application, which is used to build a complete Linux environment on Android mobile phones. It can realize many basic operations under Linux, and Termux can run normally without root permissions.

Apache is an open source web server software, widely used due to its cross-platform and security, and is one of the most popular web server software. We can use Termux to build a web server on an Android phone, and at the same time do intranet penetration, so that users on the public network can also access it, turning Android into a small cloud server.

The following describes how to build an apache service on Android Termux to create a personal site and combine it with the cpolar intranet penetration tool to achieve public network access.

1. Build apache

Execute the command to install apache, the installation is relatively simple, one-click installation

pkg install apache2

Then start apache

apachectl start

When starting up, if the following problems occur

image-20230510150038202

The solution is to modify the configuration file. If it is not installed vim, execute the command to install it.

pkg install vim

Edit and modify the configuration file

vim $PREFIX/etc/apache2/httpd.conf

Find ServerNameand untie the comment, www.example.comchange it 127.0.0.1:8080, the port number can be changed to your favorite

image-20230510151133736

After modification, start again, you can

image-20230510151344686

Open the browser, enter http://127.0.0.1:8080, you can see the apahe welcome page,

image-20230510151540948

stop apache

apachectl stop

restart apache

apachectl restart

2. Install cpolar intranet penetration

cpolar official website: https://www.cpolar.com

After successfully creating an apache container running the site, we then use cpolar to penetrate the internal network to achieve access in the public network environment.

cpolar is a secure intranet penetration cloud service, supports http/https/tcp protocols, can be used permanently for free without restricting traffic, and supports port 80/443 mapping. It can expose local services to the public network by creating a secure tunnel, so that public network users can also access intranet services normally, without the need for a public network IP or setting up a router.

Create a sources.list.dfolder of:

mkdir -p $PREFIX/etc/apt/sources.list.d

Add cpolar to download source files

echo "deb [trusted=yes] http://termux.cpolar.com termux extras" >> $PREFIX/etc/apt/sources.list.d/cpolar.list

update warehouse

pkg update

install cpolar

pkg install cpolar

Install termux service

Note: After the installation is complete, remember to close and restart termux to take effect!!

pkg install termux-services

After restarting termux, then start cpolar

sv up cpolar

Set up autostart

sv-enable cpolar

This is to stop the cpola service

sv down cpolar

cpolar.yml main configuration file path location

$PREFIX/etc/cpolar/cpolar.yml

Then we enter in the mobile browser http://localhost:9200to see the cpolar management interface, and use the email account registered on the cpolar official website to log in

image-20230509155942139

3. Public network access configuration

The mobile browser opens the cpolar web ui management interface, we click the tunnel management on the left dashboard - create a tunnel, because we modify the configuration file on the apache port (the 8080article is 8080, the specific port number is subject to your own port), so We are going to create an http tunnel pointing to port 8080:

  • Tunnel name: customizable, be careful not to repeat
  • protocol: http
  • Local address: 8080
  • Domain Type: Choose a random domain name
  • Region: Select China VIP

click创建

image-20230510153916787

After the creation is successful, open the online tunnel list, and you can see the address accessed by the public network. There are two access methods, one is http, the other is https

image-20230510155122769

We use the http method, enter the public network address in the browser, and the access is successful

image-20230510163512036

4. Fixed public network address

Since the above is a free random tunnel, the generated public network address will change randomly within 24 hours. In order to facilitate long-term and stable connection, we can fix this public network address and configure a fixed second-level subdomain name of cpolar [no filing required] , or you can configure to use your own domain name to access, here we take configuring a fixed second-level subdomain name as an example.

You need to upgrade to the basic package or above to support the configuration of second-level subdomains

Log in to the background of the cpolar official website , click on the dashboard on the left 预留, find 保留二级子域名, and reserve a second-level subdomain name for the http tunnel.

  • Region: Select the server region
  • Name: Fill in the second-level subdomain name you want to keep (customizable)
  • Description: Remarks, which can be customized

image-20230510171738839

This example reserves a mywebsitetestsecond-level subdomain named . After the subdomain name is successfully reserved, we copy the subdomain name, and then we need to configure it in the tunnel.

image-20230510171806128

隧道管理Log in to the cpolar web ui management interface, click —— on the left dashboard 隧道列表, find the tunnel that needs to be configured with a second-level subdomain name, and click on the right编辑

image-20230510171929758

Modify the tunnel information and configure the second-level subdomain name into the tunnel:

  • Domain Type: Select instead二级子域名
  • Sub Domain: Fill in the second-level subdomain name we just reserved (in this example mywebsitetest)

After the modification is complete, click更新

image-20230510172124742

状态After the tunnel is successfully updated, click —— on the left dashboard 在线隧道列表, and you can see the public network address of the tunnel, which has been updated to a second-level subdomain name.

image-20230510172216408

After fixing, we use the fixed public network address, open it in the browser, and you can see the apache default page, so that a fixed public network address access is set up

image-20230510172352811

5. Add a site

The page we visited above is the default page of apache, not the page we want. We can put the page we like on it and enter the apache htdocs folder

cd $PREFIX/share/apache2/default-site/htdocs

Install the download toolwget

pkg install wget

To demonstrate here, we download a test site

wget https://www.cpolar.com/static/downloads/meditation-app-master.tar.gz

Unzip after downloading

tar xzf meditation-app-master.tar.gz

Then we enter our public network address above plus the resource path on the browser /meditation-app-master/index.html, and we can see our personal site.

Now as long as the tunnel is kept online, public network users can access the web site we built on termux through this fixed public network address.

image-20230510182040632

Guess you like

Origin blog.csdn.net/2301_76760501/article/details/130740486