Article directory
Installing Nginx (pronounced "engine-x") turns your Raspberry Pi into a powerful web server that can be used to host websites or web applications. Compared to other web servers, Nginx has a very low memory footprint and can run on resource-constrained devices such as Raspberry Pi. At the same time, combined with the cpolar intranet penetration tool, remote access without public network IP can be achieved.
1. Nginx installation
Installing Nginx on Raspberry Pi is also very simple. You can install it directly through the apt command. Update the warehouse first.
sudo apt update
Install updates
sudo apt upgrade
After the update is complete, install the Nginx package
sudo apt install nginx
Start Nginx
sudo /ect/init.d/nginx start
After startup, we can enter the Raspberry Pi局域网ip:80
port in the external browser to access Nginx
2. Install cpolar
Use the cpolar installation script:
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
Add services to the system
sudo systemctl enable cpolar
Start cpolar service
sudo systemctl start cpolar
Check service status
sudo systemctl status cpolar
Restart the cpolar command (used when needed)
sudo systemctl restart cpolar
Then use the Raspberry Pi LAN ip+:9200 port in an external browser to display the cpolar management interface.
Enter the account registered on the official website to log in to operate the tunnel.
3. Configure domain name to access Nginx
We create a random 80 tunnel in the cpolar management interface:
- Tunnel name: Customizable, be careful not to repeat it
- Protocol: http
- Local address: 80
- Port type: random domain name
- Region: China
Click Create
Then open the online tunnel list and check the public network address where the tunnel was created. There are two access methods by default, one is http and the other is https. Copy the http address.
Open the browser and access it using the http public address above. You will see the nginx welcome interface, so the remote access is set up.
4. Fixed domain name access
It should be noted that the above steps use a random temporary address, and the public network address will change randomly within 24 hours. Next, we configure a fixed address for it. This address will not change. After setting it, there will be no need to modify the address repeatedly every day.
You need to upgrade to the basic package or above to support configuring fixed domain names.
Log incpolar official website backend, click 预留
on the left dashboard, find < a i=4>, 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
This example reserves a second-level subdomain namednginxtest
. After the subdomain name is successfully reserved, we copy the subdomain name, and then bind its configuration to the tunnel.
Log in to the cpolar web ui management interface. Click 隧道管理
——隧道列表
on the left dashboard, find the tunnel that needs to configure the second-level subdomain name, and click on the right编辑
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 case
nginxtest
)
After modification is completed, click更新
After the tunnel is updated successfully, click 状态
——在线隧道列表
on the left dashboard. You can see that the public network address of the nginx tunnel has been updated to Second-level subdomain name, copy the public address.
Open the browser and let's test accessing the successfully configured second-level subdomain name. The nginx welcome interface appears, indicating success and normal access. Now, our only private second-level subdomain name in the entire network has been created.
5. Configure static site
Enter the nginx resource directory. This directory is the resource directory that nginx looks for by default.
cd /var/www/html
In order to make the content of the site more meaningful, we download and deploy a simple static demo site – a meditation and relaxation site.
sudo wget https://www.cpolar.com/static/downloads/meditation-app-master.tar.gz
Unzip
sudo tar xzf meditation-app-master.tar.gz
Then open the browser and enter the public network address we configured above plus the resource path:/meditation-app-master
, you can see the site we configured, and remote access is also possible. a>