下载nginx-1.14.0.tar.gz
放到/usr/local/src目录下
tar -zxvf nginx-1.14.0
CentOS 7 下 安装 Nginx执行配置命令
./configure --prefix=/usr/local/nginx
时提示以下错误:
[root@localhost nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
checking for OS
+ Linux 3.10.0-123.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解决:安装gc++
执行以下命令:
yum -y install gcc gcc-c++ autoconf automake make
结果在执行yum出现error
[root@localhost nginx-1.14.0]# yum -y install gcc gcc-c++ autoconf automake make
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 13211.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 190 M RSS (1.0 GB VSZ)
Started: Tue Aug 7 21:20:31 2018 - 1:46:16 ago
State : Sleeping, pid: 13211
可以通过强制关掉yum进程:
[root@localhost nginx-1.14.0]# rm -f /var/run/yum.pid
再次configure出现
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
缺少了PCRE库
[root@localhost nginx-1.14.0]# yum -y install pcre-devel
Transaction Summary
========================================================================================================================================================
Install 1 Package
Upgrade ( 1 Dependent package)
Total size: 902 k
Total download size: 480 k
Downloading packages:
pcre-devel-8.32-17.el7.x86_64.rpm | 480 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : pcre-8.32-17.el7.x86_64 1/3
Installing : pcre-devel-8.32-17.el7.x86_64 2/3
Cleanup : pcre-8.32-12.el7.x86_64 3/3
Verifying : pcre-devel-8.32-17.el7.x86_64 1/3
Verifying : pcre-8.32-17.el7.x86_64 2/3
Verifying : pcre-8.32-12.el7.x86_64 3/3
Installed:
pcre-devel.x86_64 0:8.32-17.el7
Dependency Updated:
pcre.x86_64 0:8.32-17.el7
Complete!
再次configure
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
缺少zlib
[root@localhost nginx-1.14.0]# yum install -y zlib-devel
Transaction Summary
========================================================================================================================================================
Install 1 Package
Upgrade ( 1 Dependent package)
Total size: 140 k
Total download size: 50 k
Downloading packages:
zlib-devel-1.2.7-17.el7.x86_64.rpm | 50 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : zlib-1.2.7-17.el7.x86_64 1/3
Installing : zlib-devel-1.2.7-17.el7.x86_64 2/3
Cleanup : zlib-1.2.7-13.el7.x86_64 3/3
Verifying : zlib-devel-1.2.7-17.el7.x86_64 1/3
Verifying : zlib-1.2.7-17.el7.x86_64 2/3
Verifying : zlib-1.2.7-13.el7.x86_64 3/3
Installed:
zlib-devel.x86_64 0:1.2.7-17.el7
Dependency Updated:
zlib.x86_64 0:1.2.7-17.el7
Complete!
再次configure ok
[root@localhost nginx-1.14.0]# make && make install
查看nginx版本
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -v
启动nginx
Nginx启动文件地址】 -c 【Nginx配置文件地址】
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@localhost sbin]# ps -ef|grep nginx
root 26540 1 0 01:20 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 26541 26540 0 01:20 ? 00:00:00 nginx: worker process
root 26543 12467 0 01:20 pts/0 00:00:00 grep --color=auto nginx
[root@localhost sbin]#
三种关闭方式
从容停止 : Kill -QUIT 26540
快速停止 : kill -TERM 26540或 kill -INT 26540
强制停止 : pkill -9 nginx
重启
第一种reload命令:
[root@localhost local]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx -s reload
第二种发送信号方式:
[root@localhost local]# kill -HUP 26540