There are many ways to install Nginx. I have consulted and tried various methods, and think that the most simple and clever method is to see the method provided by the official website. Install the latest stable version of Nginx: nginx.org/en/linux_pa…

The first step

Create a new file

vim /etc/yum.repos.d/nginx.repo

Copy the code

Fill in the following, note that ‘OS’ is replaced with ‘centos’, and ‘OSRELEASE’ is replaced with ‘6’ and ‘7’ depending on the current centos version.

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

Copy the code

Please be sure to modify the content as required, otherwise an error will be reported. Example: current system: Centos7.4

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

Copy the code

Save the file and exit.

The second step

If a question similar to Is XXX OK Is displayed after you run the following command: , press y enter.

yum update
Copy the code

The third step

At this point, you can run the nginx command to install the latest stable version of nginx

yum install nginx
Copy the code

The end of the

This installation method, compared with other manual installation of a variety of packages convenient and fast, will not be due to the lack of dependencies and error, and any directory can directly execute the nginx command, do not run to the nginx directory.