1. 进入初始目录(例如我放opt中):

cd /opt/   # 进入目录

2. 下载nginx:

//下载tar包:(版本自己把控)

wget http://nginx.org/download/nginx-1.9.15.tar.gz

解压:

tar -zxvf nginx-1.9.15.tar.gz

安装:

cd nginx-1.9.15 //进入nginx目录

./configure --prefix=/usr/local/nginx   // –prefix指定安装目录

问题出现1:

./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.
解决方法:
sudo apt-get install libpcre3 libpcre3-dev
 
执行上述命令后,继续./configure --prefix=/usr/local/nginx   // –prefix指定安装目录
 
问题出现2:
./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库(版本自己把控):
cd /opt/   # 进入目录
wget http://www.zlib.net/zlib-1.2.11.tar.gz 
解压:
tar -zxvf zlib-1.2.11.tar.gz
安装:
cd zlib-1.2.11/
./configure --prefix=/usr/local/zlib
make && make install
 
如果还有错,可能还需要安装:
sudo apt-get install openssl libssl-dev
 
再执行:
cd nginx-1.9.15/
./configure --prefix=/usr/local/nginx
 不再报错,成功安装。
 
启动:
/usr/local/nginx/sbin/nginx
测试:
curl -i http://localhost
卸载:
sudo apt-get --purge autoremove nginx
查找:
which nginx