Create an Nginx container in Portainer and deploy a static web site to access the public network

Recently, I discovered a super powerful artificial intelligence learning website. It presents complex concepts in an easy-to-understand way and is entertaining. I thought it might be helpful to everyone, so I'm sharing it here. Click here to jump to the website .

Preface

Portainer is an open source Docker lightweight visualization tool that provides an intuitive web interface that allows you to easily manage and monitor Docker containers, images, networks, etc. In the previous article "Linux Docker graphical tool Portainer remote access" we talked about how to use Docker to deploy a Portainer, and combined with cpolar intranet penetration to achieve successful public network access. This article teaches you how to create an Nginx container in Portainer and deploy a static site for public network access.

1. Install Portainer

Use docker to deploy a Portainer, first pull the Portainer image

docker pull portainer/portainer

Then run the container, where: port 8098 is the Portainer web interface we want to access

docker run -d -p 8098:9000 --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce

1.1 Access the Portainer web interface

Enter http://localhost:8098 or http://server IP+8098 port number in the browser to see the Portainer management interface.

When accessing for the first time, you need to create an administrator account. Fill in the required information and set a strong password. Then click the "Create user" button to continue.

image-20231219105053262

image-20231219104918959

2. Create Nginx container using Portainer

After successfully logging in, you will see Portainer’s control panel.

Example in this article: The Web site deployed here is a three-dimensional image web page I created.

In the left navigation bar, select Home and click local

e5bc3e85b0d58174258de21390e3835

Then select Containers and click Add container in the upper right corner

3bf03ec97fce6ebda63e1f5e6693cd0

Enter the new interface:

Enter three for Name (can be customized)

Image input nginx

The external network port is customized and cannot conflict. The container port can be repeated.

c64c9b65b5678e64cabf1009f17960b

Click Volumes below , fill in the container (nginx path /usr/share/nginx/html ) and host (deployment site file path), and click Deploy the container to pull the image.

image-20231219113307790

image-20231219112539005

The creation is successful. Open a new browser and enter 127.0.0.1:8089. You can see the completed three-dimensional image.

image-20231219113625285

3. Access the static Web site from the public network

Above we created the Nginx container in Portainer and deployed a static Web site, which was successfully accessed on the LAN. Next, we install the Cpolar intranet penetration tool and forward the http public network address of the local port mapping through cpolar. We can easily achieve remote access without having to register a domain name and purchase a cloud server. The following are the steps to install cpolar.

cpolar official website address: https://www.cpolar.com

  • Use one-click script installation command
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

After cpolar is successfully installed, access Linux port 9200 on an external browser: [http://LAN ip:9200], log in with your cpolar account (if you don’t have an account, you can click below to register for free), and you can see it after logging in cpolar web configuration interface, just configure it in the web management interface

image-20231219115405508

4. Configure the public network access address of the Web site

Click Tunnel Management - Create Tunnel on the left dashboard to create a cpolar public network address tunnel for the Web 3D graphic site.

  • Tunnel name: You can customize the name. Be careful not to duplicate the existing tunnel name.
  • Protocol: Select http
  • Local address: 8089 (port for local access)
  • Domain name type: Choose a random domain name for free
  • Region: Select China Top

Click创建

image-20231219115613122

After the tunnel is successfully created, click the status on the left - online tunnel list to view the generated public network access address. There are two access methods, one is http and https

image-20231219115742114

4.1 Accessing Web sites from the public network

Copy either of the two public network addresses generated by cpolar, then open a new browser and paste the address. You can see the public network address generated by cpolar and successfully access the web site from the public network.

image-20231219120005820

For a better demonstration, we used the tunnel generated by cpolar in the aforementioned process, and its public network address was randomly generated.

The advantage of this random address is that it is established quickly and can be used immediately. However, its disadvantage is that the URL is generated by random characters and is not easy to remember (for example: 234b53d8.r1.cpolar.top). It does not look good when making a webpage to publish on the public network and share it with others. In addition, this address will change randomly within 24 hours, making it more suitable for temporary use.

I usually use a fixed second-level subdomain name because I hope that when I create a web page and share it with others, it will be a fixed and easy-to-remember public address (for example: three.cpolar.cn), which will make it more official. Facilitates communication and collaboration.

5. Fixed the public address of the static Web site

Since the tunnel created using cpolar above uses a random public network address, it will change randomly within 24 hours, which is not conducive to long-term remote access. Therefore, we can configure a second-level subdomain name for it. This address is a fixed address and will not change randomly [ps: cpolar.cn has been filed]

Note that you need to upgrade the cpolar package to a basic package or above, and the bandwidth corresponding to each package is different.

Log in to the cpolar official website , click Reserve on the left, select to reserve the second-level subdomain name, set a second-level subdomain name, click Reserve, and copy the reserved second-level subdomain name after the reservation is successful.

image-20231219133519658

After the reservation is successful, copy the name of the second-level subdomain name that was successfully reserved.

image-20231219133641998

Return to the Cpolar web UI management interface, click Tunnel Management - Tunnel List on the left dashboard, find the tunnel you want to configure, and click Edit on the right

image-20231219133724915

Modify the tunnel information and configure the successfully reserved second-level subdomain name into the tunnel.

  • Domain name type: Select a second-level subdomain name
  • Sub Domain: Fill in the successfully reserved second-level subdomain name
  • Region: China VIP

Click 更新(note, click once to update, no need to submit again)

image-20231219133923098

After the update is completed, open the online tunnel list. At this time, you can see that the public network address has changed and the address name has become a fixed second-level subdomain name.

image-20231219134008633

6. Use a fixed public address to access static Web sites

Finally, when we use a fixed public network address, we can see that the access is successful. In this way, a fixed and permanent public network address is set. You can customize the domain name anytime and anywhere and share it with others to access the web site you created. !

image-20231219134252567

Guess you like

Origin blog.csdn.net/xz2935117143/article/details/135242270