[Public network remote mobile phone Android server] Android Termux builds a web server

Table of contents

Overview

1. Build apache

2. Install cpolar intranet penetration

3. Public network access configuration

4. Fixed public network address

5.Add site


Overview

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

Apache is an open source web server software. Due to its cross-platform and security, it is widely used and is one of the most popular web server software. We can use Termux on Android phones to build a web server, and at the same time perform intranet penetration so that public network users 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 and can be installed with one click.

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">pkg <span style="color:#e6db74">install</span> apache2
</code></span></span></span></span>

Then start apache

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">apachectl start
</code></span></span></span></span>

If the following problems occur during startup

image-20230510150038202

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

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">pkg <span style="color:#e6db74">install</span> <span style="color:#e6db74">vim</span>
</code></span></span></span></span>

Edit and modify configuration files

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell"><span style="color:#e6db74">vim</span> <span style="color:#f8f8f2">$PREFIX</span>/etc/apache2/httpd.conf
</code></span></span></span></span>

Find ServerNamethe unblock comment and www.example.comchange it to 127.0.0.1:8080, you can change the port number to what you like.

image-20230510151133736

Just start it again after modifying it.

image-20230510151344686

Open the browser and enter http://127.0.0.1:8080, and you will see the apahe welcome page.

image-20230510151540948

stop apache

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">apachectl stop
</code></span></span></span></span>

Restart apache

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">apachectl restart
</code></span></span></span></span>

2. Install cpolar intranet penetration

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

After successfully creating an apache container to run the site, we next use cpolar for intranet penetration to achieve access in the public network environment.

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

Create a sources.list.dfolder of:

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell"><span style="color:#e6db74">mkdir</span> -p <span style="color:#f8f8f2">$PREFIX</span>/etc/apt/sources.list.d
</code></span></span></span></span>

Add cpolar to download source files

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell"><span style="color:#e6db74">echo</span> <span style="color:#a6e22e">"deb [trusted=yes] http://termux.cpolar.com termux extras"</span> <span style="color:#f8f8f2">>></span> <span style="color:#f8f8f2">$PREFIX</span>/etc/apt/sources.list.d/cpolar.list
</code></span></span></span></span>

update warehouse

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">pkg update
</code></span></span></span></span>

install cpolar

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">pkg <span style="color:#e6db74">install</span> cpolar
</code></span></span></span></span>

Install termux service

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

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">pkg <span style="color:#e6db74">install</span> termux-services
</code></span></span></span></span>

After restarting termux, then start cpolar

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">sv up cpolar
</code></span></span></span></span>

Set up autostart

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">sv-enable cpolar
</code></span></span></span></span>

This is to stop the cpola service

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">sv down cpolar
</code></span></span></span></span>

cpolar.yml main configuration file path location

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell"><span style="color:#f8f8f2">$PREFIX</span>/etc/cpolar/cpolar.yml
</code></span></span></span></span>

Then we enter it in the mobile browser http://localhost:9200to see the cpolar management interface. You can log in using the email account registered on the cpolar official website.

image-20230509155942139

3. Public network access configuration

Open the cpolar web ui management interface in the mobile browser. We click Tunnel Management - Create Tunnel on the left dashboard. Since we modified the configuration file on apache to be the 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 for public network access. There are two access methods, one is http and the other is https.

image-20230510155122769

We use http method and enter the public network address in the browser to access successfully.

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 stable connection, we can fix this public network address and configure a cpolar fixed second-level subdomain name [no need to register] , or you can configure it to use your own domain name for 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 subdomain names.

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

  • Region: Select server region
  • Name: Fill in the second-level subdomain name you want to reserve (can be customized)
  • Description: Notes, 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 configure it into the tunnel.

image-20230510171806128

隧道管理Log in to the cpolar web ui management interface, click - on the dashboard on the left 隧道列表, find the tunnel where you need to configure the 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 modification is completed, click更新

image-20230510172124742

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

After fixing, we use the fixed public network address, open it in the browser, and you can see the apache default page. In this way, access to a fixed public network address is set up.

image-20230510172352811

5.Add site

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

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell"><span style="color:#e6db74">cd</span> <span style="color:#f8f8f2">$PREFIX</span>/share/apache2/default-site/htdocs
</code></span></span></span></span>

Install download toolwget

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell">pkg <span style="color:#e6db74">install</span> <span style="color:#e6db74">wget</span>
</code></span></span></span></span>

For demonstration here, we download a test site

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell"><span style="color:#e6db74">wget</span> https://www.cpolar.com/static/downloads/meditation-app-master.tar.gz
</code></span></span></span></span>

After downloading, unzip it

<span style="color:#444444"><span style="background-color:#ffffff"><span style="background-color:#272822"><span style="color:#f8f8f2"><code class="language-shell"><span style="color:#e6db74">tar</span> xzf meditation-app-master.tar.gz
</code></span></span></span></span>

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

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

Guess you like

Origin blog.csdn.net/m0_68662723/article/details/132717821