Method to install Nginx under CentOS

  • 2020-05-24 06:53:32
  • OfStack

Official document: https: / / nginx org/en/linux_packages html # RHEL - CentOS

Installation environment: Linux server CentOS 7.3, Root permissions

1. Install the prerequisites:

sudo yum install yum-utils

2, To set up the yum repository, create the file named/etc/yum repos. d/nginx repo with the following contents:

(note replace OS version: $releasever, if centos version is 7, replace it with 7)

Command:

Edit the nginx.repo file using vim

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

Set Nginx's yum source:

Paste the following into the nginx.repo file


[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

Enter the vim command :wq save and exit

3. To install nginx, run the following command:

sudo yum install nginx
You will enter y to confirm the installation

4. When prompted to accept the GPG key verify that the fingerprint matches B FD6B D8BC64 1079 A5 BD82 7BD9 BF62, and if so, accept it.

Finally, fingerprint will be output. If it matches the red part above, enter y for confirmation

5. Start |, stop | and restart Nginx:


#  Start the 
systemctl start nginx.service

#  stop 
systemctl stop nginx.service

#  restart 
systemctl restart nginx.service

6. Check all installation locations of Nginx:

rpm is the rpm package management tool for linux, -q stands for query mode, and -l stands for return list

rpm -ql nginx

7. Nginx configuration file:


/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf

conclusion

The above is the site to introduce you CentOS under the installation of Nginx method, I hope to help you!


Related articles: