可直接复制粘贴运行的安装脚本
安装gcc和gcc-c++
1 | sudo yum -y install gcc |
下载pcre
1 | wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz |
下载zlib
1 | wget http://zlib.net/zlib-1.2.11.tar.gz |
pcre和zlib不需要安装,只需下载解压即可。具体说明可见官方文档
下载解压nginx
1 | wget http://nginx.org/download/nginx-1.12.1.tar.gz |
配置、编译和安装nginx
先进入到解压后的nginx目录下
–prefix是需要安装nginx的目录
–with-pcre是指定pcre的源文件目录
–with-zlib是指定zlib的源文件目录
1 | ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/src/pcre-8.41 --with-zlib=/usr/local/src/zlib-1.2.11 |
nginx 常用命令
nginx # 启动nginx
nginx -s reload # 重新载入配置文件
nginx -s reopen # 重启 Nginx
nginx -s stop # 停止 Nginx
nginx命令在nginx安装目录的sbin文件夹下
安装脚本
1 | !/bin/bash |
常见错误
checking for C compiler … not found
./configure: error: C compiler cc is not found
产生原因:
解决办法: 安装gcc编译套件1
yum -y install gcc
configure: error: You need a C++ compiler for C++ support.
make[1]: [/usr/local/src/pcre-8.41/Makefile] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.12.1’
make: [build] Error 2
产生原因: 没有安装编译套件
解决办法: 安装gcc-c++编译套件1
yum -y install gcc-c++
./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= option.
产生原因: 配置nginx时未指定pcre所在目录
解决办法: 下载解压pcre,并在配置nginx的./configure时通过–with-pcre指定pcre源码所在目录1
2wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
tar -zxvf pcre-8.41.tar.gz
./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=
产生原因: 配置nginx时未指定zlib源码所在目录
解决办法: 下载解压zlib,并在配置nginx的./configure时通过–with-zlib指定zlib源码所在目录1
2wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
tar -zxvf pcre-8.41.tar.gz