Write it at the front
If you can click in to read this article, you may have heard of itNginxThis name, want to start learning and master nginx. Maybe you are a front-end programmer, learning nginx has become a hard demand in your work.
In any case, if you are an initial contact with nginx, then this series of articles may take you step-by-step introduction to nginx. Don’t talk much nonsense. Let’s get started!
1、 What is nginx
First of all, the official definition is quoted
Nginx is an asynchronous framework HTTP web server and can also be used as a reverse proxy, load balancer, and HTTP cache. Nginx is a free open source software that is released under the terms of a BSD like license.
As an nginx Xiaobai, you don’t need to care about load balancing and reverse proxy. I will explain it later in the article. Here we only need to know the following two points:
- Nginx is a web server, supporting HTTP services, we can use it to build our server
- Nginx is open source and free, so we can use it at ease
Knowing what nginx is, we also need to understand some of its advantages:
- Support massive and high concurrency
- Less memory consumption
- Free use, commercial
- The file configuration is simple, which is very friendly to the development and operation and maintenance students
The popularity of nginx and its various advantages make it necessary for us to learn and master it. For a little white, learning nginx actually needs some foundation. Before learning, we need to prepare:
- Basic knowledge of Linux system, because the vast majority of servers are deployed on Linux servers, and the following nginx tutorial is also carried out on Linux CentOS system. Of course, you don’t need to be familiar with Linux command-line tools. You can use VIM, yum and other tools.
- A computer with Linux operating system can rent the ECS cloud server of Alibaba cloud and other manufacturers, or use a virtual machine with Linux system installed.
With some of the above conditions, let’s start installing nginx.
2、 Preliminary installation of nginx
At the time of writing this article, I was using LinuxCentOS 7If your version does not match mine, some commands may have some inconsistencies. If you encounter problems, more Baidu.
In fact, it is very convenient to install nginx on CentOSyumTo install this package management tool, first execute the following command to install some basic tools in Linux:
yum -y install gcc gcc-c++ autoconf pcre-devel make automake yum -y install wget httpd-tools vim
When installing nginx, it is recommended that you open the nginx official website first（ http://nginx.org/en/download…. ）Take a look at the current version of nginx. We don’t need to install the latest version, just install the stable version
From the figure, we can see that the current stable version of nginx is1.16.1At this time, we come to Linux to check the latest version of nginx in the current Yum package management tool. You can view it by executing the following command:
yum list | grep nginx
As can be seen from the above figure, the latest nginx version in the yum package management tool is 1.16.1, which is synchronized with the version on the official website. If the version of nginx we see here is too low or the version information of nginx is not found at all, we can use the following methods to update the yum source:
- In Linux system, execute the command:
cd /etc/yum.repos.d, switch the folder to the configuration folder of Yum source/etc/yum.repos.d
vim nginx.repo, create a new file named nginx.repo Then save all the following code to the file, save and exit.
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
Now the version of nginx in the yum source has been updated. We only need to execute the following command to install nginx very conveniently. The command is as follows:
yum -y install nginx
Wait a moment, nginx is installed successfully, execute the command
nginx -v, you can see the version of nginx successfully installed
Write it at the end
Here, we have successfully installed nginx. I hope you can follow the steps above to successfully install nginx. If you encounter any problems or errors, I hope you can actively search for information.
In the next blog, I will share with you the configuration file of nginx and how to modify it according to the actual needs. Come on!