Introduction: The last article has introduced how to install the system on the raspberry Pi, but also to recommend the debian-Pi-AARCH64 system jointly produced by OPENFANS open source community & raspberry Pi fan community, this article mainly introduces how to install Nginx in this system.
System introduction
Debian-pi-aarch64 System There are four types of debian-Pi-AARCH64 system: “Desktop Free Basic”, “Desktop Free Enhanced”, “Desktop Full Feature” and “Deep Desktop”. See the table below for the differences between these four types.
project | None Desktop Basic edition | No desktop enhancement | Full desktop edition | The depth of the desktop |
---|---|---|---|---|
KVM hardware virtualization support | u | u | u | u |
Vm graphical control terminal | X | X | u | X |
Docker container support | Do things | u | Do things | Do things |
CecOS CaaS container cloud support | Do things | Do things | Do things | X |
WebGUI management platform | X | u | u | X |
Web SSH client support | u | u | u | u |
Standard VM suite | u | u | u | X |
Pagoda Virtual Machine Suite | u | u | u | X |
If you are already familiar with Linux system, this column recommends installing “No Desktop Enhanced Edition” system comes with Docker and starts by default, saving the time of installing Docker. If you are not familiar with Linux or you want to install a system with desktop, you can choose according to your own needs. If you want to achieve the goal in one step, It is still recommended to install the Full Desktop edition.
The installation of the Nginx
Start the docker
Debian-pi-aarch64 does not have Docker enabled by default, but some versions do not have Docker enabled by default. If you do not have a desktop enhanced version installed, you can use the following command to start Docker
Manual enable: systemctl start docker.service Enable Startup upon startup: systemctl enable docker.serviceCopy the code
The following command is used to stop Docker
Manual stop: systemctl stop docker.service Disable the startup upon system startup: systemctl disable docker.serviceCopy the code
After starting, you can use the following command to check the running status of docker
systemctl status docker
Copy the code
If the following figure is displayed after the command is executed, the startup is successful.
Install Nginx using Docker
Once Docker is started, installing Nginx is easy. It only takes a few steps to successfully install Nginx.
-
Pull the Nginx image locally by using the following command
docker pull nginx Copy the code
-
Create and start Nginx
docker run -d --name mynginx -p 88:80 nginx Copy the code
- -d Specifies the container to run in background daemon mode
- –name specifies the container name, in this case MYnginx
- -p Specifies the port number mapping between the host and the container. The format is -p [host port number] : [Container internal port]. Here, I use port 88 on the host and port 80 on the container
- Finally, the name of the Nginx image
-
Check whether the Nginx container was started successfully
docker ps Copy the code
If the status is Up, the startup is successful.
-
Enter raspberry PI IP :88 in the browser, and the following screen is displayed
If the preceding page is displayed, Nginx has been successfully installed.
How to change the default configuration of Nginx
However, the problem is that our current Nginx is installed in the Docker environment, what if we want to change the default configuration of Nginx? There are two methods:
- Enter the container to modify
- Use file mapping to map Nginx files in docker containers to hosts
These two methods are described in detail below.
Enter the container and modify the configuration
To enter the docker environment running Nginx, run the following command
docker exec -it mynginx /bin/bash
Copy the code
-
The exec command represents attaching to the inside of the running container
-
It is a combination of the -i and -t arguments. -I -t indicates that a TTY has been created for our specified container and STDIN has been captured
-
Mynginx is the name of the container we are going to enter
-
/bin/bash Specifies the shell to execute the command
The following page is displayed after the command is executed
Once inside the nginx container, we cancd /etc/nginx
, you can see the relevant nginx configuration files are in/etc/nginx
directory
In the figure above, we do not find the default home page HTML file directory in the nginx container. This is because the default home page HTML file directory is /usr/share/nginx/html, while the log file is located in /var/log/nginx.
At this point, you have found the corresponding file of Nginx, if you want to modify the corresponding file can directly modify. Every time you want to modify a file, you have to enter the docker container, which is too tedious. Here is a simple method. As long as you map the files that often need to be modified or viewed to the host, you can directly operate the files mapped to the host in the future.
Map files in the Docker container to the host
Mount the nginx container internal configuration file to the host, and then modify it in the corresponding directory of the host. Here are the steps
-
Create a mount directory
sudo mkdir -p /mnt/nginx/{conf,html,logs} Copy the code
After the file is created, the following directories are displayed
-
Copy the nginx.conf and default.conf files in the container to the host/MNT /nginx and directory/MNT /nginx/conf respectively
sudo docker cp mynginx:/etc/nginx/nginx.conf /mnt/nginx Copy the code
sudo docker cp mynginx:/etc/nginx/conf.d/default.conf /mnt/nginx/conf/ Copy the code
-
Check the Nginx container ID you just created
docker ps Copy the code
-
Stop the nginx container you just created
Docker stop 74CA40396f6bCopy the code
-
Delete the nginx container you just created
Docker RM 74CA40396F6bCopy the code
-
Run the following command to recreate the nginx container
sudo docker run -d --name mynginx --restart=always -p 88:80 -v /mnt/nginx/nginx.conf:/etc/nginx/nginx.conf -v /mnt/nginx/logs:/var/log/nginx -v /mnt/nginx/html:/usr/share/nginx/html -v /mnt/nginx/conf:/etc/nginx/conf.d --privileged=true nginx Copy the code
- -v Indicates the directory to be mounted. The format is -v: the host directory and container directory are shared.
- — Privileged =true The container has read and write privileges for the mounted directory
- –restart=always: the system will restart if a failure occurs
-
Revisiting raspberry PI IP :88 will bring up the 403 screen, as follows
This is because the HTML file mounted to the host is empty, now put my blog file in the HTML folder, visit again, the following screen appears
This completes the successful mount of the files in the Nginx container to the host.
conclusion
This article first introduces how to choose a suitable system among the four versions of the system, then introduces how to open and close the system docker, and then introduces how to install Nginx in Docker. Finally, in order to facilitate the modification of files in Nginx, This section describes how to mount nginx files in Docker to local.
This article has completed the installation of Nginx on raspberry PI, but it is not perfect, now can only access our Nginx content on the Intranet, the next article will introduce how to access our Nginx through the public network, the real raspberry PI server, please look forward to.
Finally, welcome to my raspberry PI blog, Pi.wizardev.cn :88.
This article was first published by the public account “Code Lover”