Install Nginx server on CentOS 7

Below I will make a simple record of my experience in installing Nginx on CentOS for future reference.

1、 Download the nginx-release package

Take CentOS 7 as an example, download the nginx software package: http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Download address of software packages for other Linux distributions: http://nginx.org/en/linux_packages.html

2、 Log in to the terminal as a normal user, and then import the GPG signing key.

$ sudo rpm --import"http://nginx.org/keys/nginx_signing.key"

3、 Install the software package downloaded in 1.

$ sudo yum install /home/sue/download/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Where "/home/sue/download/" is the storage path of the software package.

4、 Install nginx server

$ sudo yum install nginx

At this point, if there are no accidents, the installation is complete, and the next step is to configure the server.

After installing nginx, let's take a look at where nginx is installed.

$ whereis nginx

After executing the command, the system prompts the following location:

nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz

Then we can easily know where the configuration file of the nginx server is located: /etc/nginx

Then we check which configuration files are in this directory:

$ cd /etc/nginx 
$ ls -l

After executing this command, we can see some file lists, but we only need to view the contents of the "nginx.conf" file, which is the configuration file of the nginx server:

$ cat -n nginx.conf

Note: If the selected nginx installation package is "Nginx for CentOS 6", the path of the configuration file may not be this path, it may be the path /etc/nginx/conf.d/default.conf.

As can be seen from the above configuration items, the default listening port of the server is port 80, the server name (which can also be a domain name) is localhost (127.0.0.1), and the root directory of the server is "/usr/share/nginx/html". If the server starts normally, then we can directly enter "localhost" or "127.0.0.1" in the address bar of the browser, and we should be able to see the default home page. Below we start the nginx server:

$ sudo nginx

If an error is reported, you need to execute the following command after the previous command is executed:

$ sudo nginx -s reload

If no error is reported, open the browser and enter "127.0.0.1" in the address bar to see the default home page as follows:

In addition, Nginx has the following commonly used command line parameters:

. /nginx 
. /nginx -s stop
. /nginx -s quit
. /nginx -s reload
. /nginx -s quit:The stopping step in this way is to stop when the nginx process finishes processing tasks.
. /nginx -s stop:This method is equivalent to first finding out the nginx process id and then using the kill command to forcefully kill the process.

Recommended Posts

Install Nginx server on CentOS 7
install virtualbox on centos server
Centos7 install Nginx
How to install Nginx on CentOS 8
Install Docker on Centos7
install LNMP on centos7.4
Install Java on Centos 7
Nodejs install on centos7
Install FFmpeg on CentOS 8
Install RabbitMQ on CentOS 7
Install Node.js on Centos
Maven install on centos7
Install MongoDB on CentOS 7
Install Surelog on CentOS8
Openjdk install on centos7
Install Jenkins on centos7
install RabbitMQ on centos
ubuntu install nginx server
install oracle on centos
Install RabbitMQ on CentOS7
Install mysql online on centos
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Install ElasticSearch 7.x on CentOS 7
Install MySQL 8.0.16 on Linux Centos
Install docker transfer on Centos7
Install docker on Centos system
Tencent Cloud Centos install nginx
install EPEL repo on centos
How to install and configure NFS server on CentOS 8
1.5 Install Centos7
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
Install JDK8 in rpm on CentOS7
How to install Memcached on CentOS 8
Install MATE or XFCE on CentOS 7
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install Nginx on Ubuntu 20.04
CentOS 7 install Nginx, PHP, MySQL packages
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
Tencent Cloud Centos7 install java server
How to install Git on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
Tencent Cloud Centos7 install java server
How to install GCC on CentOS 8
Install Percona Server database (in CentOS 8)
How to install Yarn on CentOS 8
How to install Asterisk on CentOS 7
Install MySQL on Linux CentOS7 (Windows)
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8