查看CentOS版本:
cat /etc/redhat-release
[root@data1 nginx-1.14.0]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
最新稳定版Nginx地址:
http://nginx.org/download/nginx-1.14.0.tar.gz
1.下载Nginx:
wget http://nginx.org/download/nginx-1.14.0.tar.gz
[root@data1 application]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
--2018-07-24 20:04:48-- http://nginx.org/download/nginx-1.14.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2001:1af8:4060:a004:21::e3, ...
正在连接 nginx.org (nginx.org)|206.251.255.63|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1016272 (992K) [application/octet-stream]
正在保存至: “nginx-1.14.0.tar.gz”
100%[================================================================================================================================================================================================>] 1,016,272 25.8KB/s 用时 47s
2018-07-24 20:05:36 (21.0 KB/s) - 已保存 “nginx-1.14.0.tar.gz” [1016272/1016272])
2.解压
tar zxvf nginx-1.14.0.tar.gz
[root@data1 application]# tar zxvf nginx-1.14.0.tar.gz
3.生成配置
3.1 先进入解压后的文件夹
[root@data1 application]# cd nginx-1.14.0
[root@data1 application]# cd nginx-1.14.0
3.2 生成配置
[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
checking for OS
+ Linux 3.10.0-514.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
提示找不到C编译器
3.3 安装C编译器
[root@data1 nginx-1.14.0]# yum -y install gcc gcc-c++ autoconf automake make
[root@data1 nginx-1.14.0]# yum -y install gcc gcc-c++ autoconf automake make
等待安装完成
再执行生成配置的命令
[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
checking for OS
+ Linux 3.10.0-514.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
checking for gcc -pipe switch ... found
...
省略
...
./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库
3.4 安装pcre
[root@data1 nginx-1.14.0]# yum install pcre
[root@data1 nginx-1.14.0]# yum install pcre
再执行生成配置的命令
[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
./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-devel
[root@data1 nginx-1.14.0]# yum install pcre-devel
[root@data1 nginx-1.14.0]# yum install pcre-devel
再执行生成配置的命令
[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
./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.
缺少gzip库
3.5 安装gzip
[root@data1 nginx-1.14.0]# yum install -y zlib-devel
[root@data1 nginx-1.14.0]# yum install -y zlib-devel
再执行生成配置的命令
[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
出现以上内容就表示检测通过了, 生成配置文件Makefile
3.6 编译安装
[root@data1 nginx-1.14.0]# make && make install
[root@data1 nginx-1.14.0]# make && make install
make -f objs/Makefile
make[1]: 进入目录“/application/nginx-1.14.0”
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
...
省略
...
make[1]: 离开目录“/application/nginx-1.14.0”
安装完毕!
3.7 启动Nginx服务并查看监听端口
[root@data1 nginx-1.14.0]# cd /usr/local/nginx/sbin/
[root@data1 sbin]# ./nginx
[root@data1 sbin]# netstat -antp
[root@data1 nginx-1.14.0]# cd /usr/local/nginx/sbin/
[root@data1 sbin]# ./nginx
[root@data1 sbin]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9869/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 530/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 783/master
tcp 0 0 192.168.190.11:22 192.168.190.1:3794 ESTABLISHED 2573/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 530/sshd
tcp6 0 0 ::1:25 :::* LISTEN 783/master
可以看出Nginx监听的是80端口
如果启动失败,可能是其他程序占用了80端口