Use docker + Fast Reverse Proxy + Nginx Proxy Manager to turn an old computer into a new server
Everyone has more or less the need to access their own home devices when they are outside, but it is time-consuming and laborious to configure the home network with ipv6 or public ipv4. Here I recommend using frp to penetrate the intranet so that the home network can be accessed externally. This only requires a device with a public network, and the easiest way for that is to buy a server.
Here I recommend vultr, which has nodes to choose from in many cities around the world. Cloud computing costs as little as $6 a month. I used it for quite a long time until I graduated and had no source of income.
If you are as poor as me, then I recommend you to use cloudcone, which often has activities. Even in the absence of activities, the minimum configuration only costs $21.6 a year.
After deploying your own vps according to your own preferences (it is recommended to use Linux, this article will introduce the Ubuntu system as the background), you need to install Docker next.
Install Docker
Why install Docker? Docker is a widely used containerization technology that provides a lightweight, portable and efficient way to build, run and share applications. It is a magic tool for those who are not good at environment configuration. You only need to pull the image and run the container to easily run the service. You no longer have to worry about running a lot of scripts and getting a lot of errors, and then checking for a long time and finally giving up.
It is best to refer to the docker official website for installation. Generally, refer to the 3 steps under Install using the apt repository
to successfully install.
If you are really lazy and don’t want to read the official website introduction, then copy the following command to the command line
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
PS: Generally, if you log in to the vps as root, you can skip sudo
Install npm
This npm is not that npm. The npm here refers to nginx proxy manager. If you are willing to read the document yourself, it is recommended to read the document to deepen your understanding of npm. If you do not need to configure the domain name to directly connect to the corresponding web service and apply for ssl and other services, you can skip this step.
To install npm, you only need to create an empty directory and then enter this directory
# to home directory
cd ~
# create a directory named npm
mkdir npm
# go to directory
cd ./npm
# create docker compose configuration file
touch docker-compose.yml
# create docker network
sudo docker network create npmcontrol
The purpose of creating a docker network is to make all docker containers in the same network, which will facilitate the subsequent management of npm.
Copy the following configuration file to docker-compose.yml
:
version: '3.8'
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
# These ports are in format <host-port>:<container-port>
- '80:80' # Public HTTP Port
- '443:443' # Public HTTPS Port
- '81:81' # Admin Web Port
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
networks:
default:
external: true
name: npmcontrol
Save and use sudo docker compose up -d
in command line
When you see something like container npm-app-1 running
, it means you have installed npm.
Now open the browser and enter http://ip:81
(usually the public ip of the vps will be displayed on the operator's page and will be told directly). If you don't know your ip, you can also use the following command:
ifconfig
After the result comes out, find eth0
, and the following inet
is generally your public ip.
After accessing the browser, you will see the npm login interface, the default account password is
Email: [email protected]
Password: changeme
After logging in, you will be asked to change your email password.
If you plan to use npm to play its role, then you need to have one or more domain names and bind them to your cloud server.
As usual, enter http://ip:81
in the browser and log in, and perform the following steps respectively
- Select hosts -> proxy hosts
- Click add proxy host
- Fill in the domain name you just bound, such as
npm.domain.com
- Fill in
npm
in the forward hostname/IP column (if you have given your npm a different container name, fill in that one), - Fill in
81
in the forward port - You can learn about the following three functions to decide whether to open or not.
- In addition, if you want to access via https, then click ssl and select request a new ssl certificate.
- Click save
- Wait a moment and you can access your npm through
npm.domain.com
.
Install frp
frp refers to fast reverse proxy, which is divided into frps and frpc. s stands for server, c stands for client.
First, let's install the client
Local computer
Please make sure that docker is installed on your local computer. If not, please follow the steps above to install docker. In addition, the local computer may need to configure user groups, which is also introduced on the official website. Please comment if you have any needs.
- Create a folder
# to home directory
cd ~
# create a directory named npm
mkdir frpc
# go to directory
cd ./frpc
# create docker compose configuration file
touch docker-compose.yml
# create frps configuration file
touch frpc.toml
- Copy the following configuration
# docker-compose.yml
services:
frps:
image: 'snowdreamtech/frpc'
restart: always
network_mode: "host"
volumes:
- './frpc.toml:/etc/frp/frpc.toml'
Here, you can use the host network to monitor all ports on the host without having to manually add them to docker-compose.yml
.
3. After saving, we also need to configure frpc
# frpc.toml
serverAddr = "your.ip.add.ress"
serverPort = 7000
auth.method = "token"
auth.token = "yourtoken"
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000
Here, an ssh proxy is added. If the fprs on the vps is successfully configured, you can use ssh -P 6000 user@ip
to connect to the local shell. (user is the username of your local computer user, but ip is your public network ip. If you don't know, you can refer to the introduction of installing npm above). In addition, auth is the authentication you need. If you don't need or don't want to add authentication, just delete it (remember to delete frps.toml
as well).
4. Run the command in command
sudo docker compose up -d
vps
- Similarly, create a folder
# to home directory
cd ~
# create a directory named npm
mkdir frps
# go to directory
cd ./frps
# create docker compose configuration file
touch docker-compose.yml
# create frps configuration file
touch frps.toml
- Copy the following configuration
# docker-compose.yml
services:
frps:
image: 'snowdreamtech/frps'
restart: always
volumes:
- './frps.toml:/etc/frp/frps.toml'
ports:
# if any more ports require add here
- "7000:7000"
- "6000:6000"
# if you don't use npm ignore following
networks:
default:
external: true
name: npmcontrol
- After saving, we also need to configure frps
# frps.toml
bindPort = 7000
auth.method = "token"
auth.token = "yourtoken"
The port here is 7000. If you need to change it to another port, remember to make corresponding changes in the frpc configuration of the local computer and the above docker-compose.yml
. In addition, if you don't want to connect to require authentication, you can delete the two lines of auth, and also delete the auth of the local computer.
- Use in command line
sudo docker compose up -d
This is how the deployment is done. Use sudo docker log frps
to check whether the connection is successful. You can also use the method of connecting to ssh described above to test whether the connection is successful.
Connect to the local web service externally
Suppose I have a web service running on local port 8080, which can be accessed through the browser localhost:8080
on my computer. Then I just need to add a new
[[proxies]]
name = "my local web service"
type = "tcp"
localIP = "127.0.0.1"
localPort = 8080
remotePort = 8080
Here remote port refers to the port in frps's docker network, please make sure it is not occupied. After adding, use:
sudo docker compose restart
Setup without npm
If you don't plan to use npm, connect to the cloud service now, in the file ~/frps/docker-compose.yml
# docker-compose.yml
services:
frps:
image: 'snowdreamtech/frps'
restart: always
volumes:
- './frps.toml:/etc/frp/frps.toml'
ports:
# if any more ports require add here
- "7000:7000"
- "6000:6000"
- "8080:8080"
# if you don't use npm ignore following
networks:
default:
external: true
name: npmcontrol
Added port 8080, now use:
sudo docker compose restart
Then wait a moment, you can use ip:8080
to access your intranet service!
Setup with npm
Using npm is no different from setting up npm.domain.com
at the beginning.
Enter https://npm.domain.com
in the browser and log in (if you don't have ssl, enter http://npm.domain.com
. If you don't have a domain name for npm, go back to install npm and set it up (if you don't want to, you can just do the following)), and perform the following steps respectively
- Select hosts -> proxy hosts
- Click add proxy host
- Fill in the domain name you just bound in domain names, such as
inetwebservice.domain.com
- Fill in
frps
in the forward hostname/IP column (if you have given your frps a different container name, fill in that one), - Fill in
8080
for forward port (fill in the remote port in frpc) - The following three can be understood to decide whether to open or not.
- In addition, if you want to access via https, click ssl and select request a new ssl certificate.
- Click save
- After a while, you can access your intranet application through
inetwebservice.domain.com
.