Install nginx on CentOS7

1. gcc installation To
install nginx, you need to compile the source code downloaded from the official website first. The compilation depends on the gcc environment. If there is no gcc environment, you need to install:


yum install gcc-c++
2. PCRE pcre-devel Install
PCRE (Perl Compatible Regular Expressions) Yes A Perl library, including a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux. pcre-devel is a secondary development library developed with pcre. nginx also requires this library. Command:


yum install -y pcre pcre-devel
3. zlib Installing
the zlib library provides a variety of compression and decompression methods. nginx uses zlib to gzip the contents of the http package, so the zlib library needs to be installed on Centos.


yum install -y zlib zlib-devel
4. OpenSSL installation
OpenSSL is a powerful secure socket layer cryptographic library, including major cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocols, and provides rich applications For testing or other purposes.
Nginx supports not only the http protocol, but also https (that is, transmitting http over the ssl protocol), so you need to install the OpenSSL library on Centos.


yum install -y openssl openssl-devel


use wget command to download (recommended).


wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
decompression is


still a direct command:


tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
configuration


Actually in nginx -In version 1.10.1, you don't need to configure related things, the default is fine. Of course, it is also possible if you want to configure the directory yourself.
1. Use the default configuration


./configure to


compile and install


make
make install
Find the installation path:


whereis nginx


start and stop nginx


cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s quit
./ nginx -s reload
./nginx -s quit: The stopping step of this method is to stop the nginx process after the processing task is completed.
./nginx -s stop: This method is equivalent to first finding out the nginx process id and then using the kill command to forcibly kill the process.


Query the nginx process:


ps aux|grep nginx to
restart nginx


1. Stop and then start (recommended):
Restarting nginx is equivalent to stopping and then starting, that is, executing the stop command before executing the start command. As follows:


./nginx -s quit
./nginx
2. Reload the configuration file:
when the configuration file nginx.conf of nginx is modified, you need to restart nginx to make the configuration take effect. Use -s reload without first stopping nginx and restarting nginx can make the configuration information take effect in nginx, as follows:
./nginx -s reload


self-


start at boot It is enough to add the startup code in rc.local.


vi /etc/rc.local
add a line /usr/local/nginx/sbin/nginx
to set the execution permission:


chmod 755 rc.local

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325730791&siteId=291194637
Recommended