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