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 with 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 realized.
1. Nginx installation
It is also very simple to install Nginx on the Raspberry Pi. You can install it directly through the apt command, and update the warehouse first.
sudo apt update
install updates
sudo apt upgrade
Install the Nginx package after the update is complete
sudo apt install nginx
Start Nginx
sudo /ect/init.d/nginx start
After starting, we can enter the Raspberry Pi port in the external browser 局域网ip:80
to access Nginx
2. Install cpolar
Use the cpolar one-piece installation script:
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
Add a service to the system
sudo systemctl enable cpolar
Start the cpolar service
sudo systemctl start cpolar
View service status
sudo systemctl status cpolar
Restart the cpolar command (use 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
- protocol: http
- Local address: 80
- Port type: random domain name
- Region: China
click create
Then open the online tunnel list and view the public network address for creating the tunnel. There are two access methods by default, one is http and the other is https, copy the http address
Open the browser, use the above http public network address to access, you can see the nginx welcome interface, so that 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, which will not change, and there is no need to modify the address every day after setting.
You need to upgrade to the basic package or above to support the configuration of fixed domain names
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
This example reserves a nginxtest
second-level subdomain named . After the subdomain name is successfully reserved, we copy the subdomain name, and then we need to 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 example
nginxtest
)
After the modification is complete, click更新
状态
After the tunnel is successfully updated, click —— on the left dashboard 在线隧道列表
, and you can see the public network address of the nginx tunnel, which has been updated to a second-level subdomain name, and copy the public network address.
Open the browser, let's test the access to the successfully configured second-level subdomain name, and 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 a static site
Enter the nginx resource directory, which 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 – meditation and relaxation site.
sudo wget https://www.cpolar.com/static/downloads/meditation-app-master.tar.gz
decompress
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 available.