Raspberry Pi uses Nginx+cpolar intranet penetration to access local sites on the intranet without public IP

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 usage 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 starting, we can enter the Raspberry Pi port in the external browser 局域网ip:80to access Nginx

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-0hSIHm6L-1693204335785)(https://images.cpolar.com//img/image-20230607131709841.png) ]

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

View 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.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-WmMYhd9t-1693204335786)(https://images.cpolar.com//img/image-20230607133940058.png) ]

Enter the account registered on the official website to log in to operate the tunnel.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-cTO1xxwT-1693204335787)(https://images.cpolar.com//img/image-20230303184844558.png) ]

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

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-OEkWsufy-1693204335787)(https://images.cpolar.com//img/image-20230607134925374.png) ]

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.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-dhhEEplt-1693204335787)(https://images.cpolar.com//img/image-20230607134956379.png) ]

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.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-kUdpw7zc-1693204335787)(https://images.cpolar.com//img/image-20230607135233922.png) ]

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

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-vyCtxsTB-1693204335787)(https://images.cpolar.com//img/image-20230607140809246.png) ]

This example reserves a nginxtestsecond-level subdomain named . After the subdomain name is successfully reserved, we copy the subdomain name, and then bind its configuration to the tunnel.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-pmyFofky-1693204335788)(https://images.cpolar.com//img/image-20230607140853198.png) ]

Log in to the cpolar web ui management interface. 隧道管理Click - on the dashboard on the left 隧道列表, find the tunnel that needs to be configured with a second-level subdomain name, and click on the right编辑

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-nY3Id7uz-1693204335788)(https://images.cpolar.com//img/image-20230607140924625.png) ]

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 modification is completed, click更新

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-PmNbtD0t-1693204335788)(https://images.cpolar.com//img/image-20230607141008024.png) ]

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

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-wtkj4Noo-1693204335788)(https://images.cpolar.com//img/image-20230607141038162.png) ]

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.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-KZQntzWp-1693204335789)(https://images.cpolar.com//img/image-20230607141122878.png) ]

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.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-xsJLuAUK-1693204335789)(https://images.cpolar.com//img/image-20230607151025731.png) ]

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.

[External link pictures are being transferred...(img-xsJLuAUK-1693204335789)]

Guess you like

Origin blog.csdn.net/qq_43289447/article/details/132538426