Can you build a personal blog on your mobile phone? Build your own blog website with Android Termux+Hexo

Article directory

    • Preface
  • 1. Install Hexo
  • 2.Install cpolar
  • 3.Remote access
  • 4. Fixed public network address

Foreword

Hexo is a fast, simple and efficient blogging framework written in Nodejs. Hexo uses Markdown to parse articles and generate static web pages with beautiful themes in a few seconds.

The following describes how to install a personal hexo blog in Termux and combine it with the cpolar tool to achieve remote access.

1. Install Hexo

Hexo is written in Nodejs, so if you want to install it, install node.js first. Termux is also encapsulated. You can install it with one line of commands:

pkg install nodejs

After installation, use the npm command to install hexo:

npm install hexo-cli -g

After the installation is complete, check the version information to verify whether the installation was successful:

hexo -v

image-20230512133528614

Manually create a hexo directory:

mkdir hexo

Enter directory

cd hexo

Initialize the Hexo environment

hexo init

After initialization, static files are generated:

hexo g

Start hexo

hexo s

After starting, we can see the accessed address and port number

image-20230512134826015

We open the browser and enter the access link above to see hexo

image-20230512135104828

The above startup method is to start hexo in the foreground interface, which is not very convenient for us to do other operations, so we change to background startup. First use the Ctrl + C keys to stop hexo.

Then we use nohup to start in the background. After starting, we can press the PID:

nohup hexo s &

image-20230512140634188

The way to close is also very simple, use the kill command:

kill -9 PID

Above we have installed the hexo blog, now we will install cpolar

2. Install cpolar

Create a folder sources.list.d:

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 repository

pkg update

Install cpolar

pkg install cpolar

Install the termux service, note: After the installation is completed, remember to close and restart termux for it to take effect!!

pkg install termux-services

After restarting termux, then start cpolar

sv up cpolar

Set up auto-start at power on

sv-enable cpolar

This is to stop the cpolar service

sv down cpolar

cpolar.yml main configuration file path location

$PREFIX/etc/cpolar/cpolar.yml

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

image-20230509155942139

3.Remote access

Open the cpolar management interface in the mobile browser. We click Tunnel Management – Create Tunnel on the left dashboard. Above we see through local access that the port number is 4000, so we need to create an http tunnel. Point to port 4000:

  • Tunnel name: Customizable, be careful not to repeat it
  • Protocol: http
  • Local address: 4000
  • Domain name type: Choose a random domain name
  • Region: Select China VIP

Click Create

image-20230512150045998

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-20230512150926656

Then we use one of the http methods to access it in the browser, and we can see our Hexo blog interface, so that the remote access is configured.

image-20230512151135860

4. Fixed public network address

The above creation is a free random address that changes within 24 hours. In order to facilitate long-term and stable connections, we can fix the access address, which is called a fixed second-level subdomain name in cpolar. Of course, you can also configure and use your own domain name for access.

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 Reserve on the left dashboard, find Reserve second-level subdomain name, 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-20230516141511164

This example reserves a second-level subdomain named hexoblog. After the subdomain name is successfully reserved, we copy the subdomain name and then configure it into the tunnel.

image-20230516141541897

Log in to the cpolar web ui management interface, click Tunnel ManagementTunnel List on the left dashboard, find the tunnel that needs to be configured with a second-level subdomain name, and click Edit

image-20230516142410556

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

  • Domain name type: select Second-level subdomain name instead
  • Sub Domain: Fill in the second-level subdomain name we just reserved (in this case, hexoblog)

After the modification is completed, click Update

image-20230516142441119

After the tunnel is successfully updated, click StatusOnline Tunnel List on the left dashboard. You can see that the public network address of the tunnel has been updated to a second-level subdomain name.

image-20230516142517920

Then we use one of the http methods to access the browser, and we can see our Hexo blog interface. In this way, a fixed remote access to the hexo blog is configured [cpolar.cn has been filed, so no filing is required].

We only need to keep the tunnel online, and public network users can access the blog website on the mobile phone termux through this public network address.

image-20230516143034891